Powershell One-liner for finding all objcets that use a spesific domain name in Exchange Online

In some cases we need to find all objects that use a domain name in Exchange Online or Azure AD. For example when we need to remove a domain from a Office 365 tenant. This is not a easy task, unless we are able to script it.

The following three one-liners prints out all email addresses that is active on a object.

Get all users with @mydomain.com

Get-MsolUser -DomainName "mydomain.com"

Get all distribution groups with @mydomain.com

Get-DistributionGroup | foreach {$_.EmailAddresses | ? {$_ -like "*@mydomain.com"}}

Get all dynamic distribution groups with @mydomain.com

Get-DynamicDistributionGroup | foreach {$_.EmailAddresses | ? {$_ -like "*@mydomain.com"}}

Thereafter we can either go in and remove these manually, or we could write a new script that does it for us using the Set-MailUser, Set-Mailbox, Set-DistributionGroup or Set-DynamicDistributionGroup

Microsoft introduced the Azure Automation Runbook Gallery

Yesterday, Microsoft introduced the Azure Automation Runbook Gallery.  This new feature gives you a growing list of runbooks, that’s already polished and ready for use.

In other words, it just got much faster to achieve your automation goal without being a hard core PowerShell guru.

Read a more about it at the Microsoft Azure Blog http://azure.microsoft.com/blog/2014/10/07/introducing-the-azure-automation-runbook-gallery/

New release of Azure PowerShell – Version 0.8.8 is here

A new Azure PowerShell release is available. To upgrade, click this link http://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409 or follow the guide from the Microsoft Azure Documentation http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/

PowerShell 5 Preview is here

Windows Management Framework 5 Preview has been released, and can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?id=42316.

You can see some of the new features below and take a look at this blog post for more details http://blogs.technet.com/b/windowsserver/archive/2014/04/03/windows-management-framework-v5-preview.aspx

Network Switch Cmdlets

The Network Switch Cmdlets enable you to do switch, VLAN and basic Layer 2 network switch port configuration to Windows Server 2012 R2 Logo certified Network switches. Microsoft remains committed to support the Data Center Abstraction vision (DAL) and to show value for our customers and partners in this space. Using these cmdlets you can do:

  • Global switch configuration, such as:
    • Setting host name
    • Setting switch banner
    • Persist configuration
    • Enable or disable feature
  • VLAN configuration:
    • Create or remove VLAN
    • Enable or disable VLAN
    • Enumerate VLAN
    • Set friendly name to a VLAN
  • Layer 2 port configuration:
    • Enumerate ports
    • Enable or disable ports
    • Set port modes and properties
    • Add or associate VLAN to Trunk or Access on the port


OneGet is a new way to discover and install software packages from around the web. With OneGet, you can:

  • Manage a list of software repositories in which packages can be searched, acquired, and installed
  • Search and filter your repositories to find the packages you need
  • Seamlessly install and uninstall packages from one or more repositories with a single PowerShell command



Quickly add license option for all your users in Office 365

Just a simple PowerShell one liner for adding a new license pack for all your users in Office 365. Quite handy while in trial, and you just added for example the CRM Online pack.

First connect to Microsoft Online using PowerShell, and run Get-MsolAccountSku

That should return something like this

PS C:\Users\Anders> Get-MsolAccountSku

AccountSkuId          ActiveUnits     WarningUnits    ConsumedUnits
------------          -----------     ------------    -------------
aeb07:CRMSTANDARD     25              0               0
aeb07:ENTERPRISEPACK  25              0               24

Then simply run this command, and replace AccountSkuId, with the ID from the table above

Get-MsolUser | where {$_.isLicensed -eq $true} | Set-MsolUserLicense -AddLicenses "AccountSkuId"

This command simply gets all users in Office 365, and select only those who are licensed today, and then add the license. You can filter as you like in the where statement.