Blog‎ > ‎Office 365‎ > ‎

Useful Powershell Cmdlets

Export users licenses and information O365

In order to Export users licenses and information from Office 365 you will have to use the following script.

First you will need to connect to MS Online service with a Global admin account



Get-MsolUser -All |Where {$_.IsLicensed -eq $true } |Select DisplayName,UsageLocation,@{n="Licenses Type";e={$_.Licenses.AccountSKUid}},SignInName,UserPrincipalName,@{n="ProxyAddresses";e={$_.ProxyAddresses}}| Export-csv -Path C:\ExportlicenseUsage.csv –notype


This will export a file called “ExportLicenseUsage.csv” to your C root drive. you can open this file with Microsoft Excel and find out all the useful information that you’re looking for.

Hope this helps Smile 

Testing Office 365 SMTP relay

In order to test Office 365 SMTP relay you will have to create a user with an Exchange online license. After the email is activated for this user you can test this user for relay with the following powershell.

First connect to Microsoft Online service with this user that you’ll be using for relaying.

$msolcred = Get-Credential

Next edit the following powershell with the user’s e-mail and the recipient's too

Send-MailMessage –From –To –Subject “Test Email” –Body “Test SMTP Relay Service” -Credential $msolcred -UseSsl -Port 587



This test is known as Client SMTP submission you can also use a different method for multiple devices where you can configure them all to point to a single server (IIS) in a method known as IIS for relay with Office 365 however, all the methods what involve office 365 (Only) for relay will require a user with Exchange online license assigned to it.

Search for users start with particular letters in the display name


To search your Office 365 users with particular initial characters

First connect to Microsoft Online Service




To Search for users whom their display names contain “Top” you can use the following powershell

get-msoluser -all | where-object {$_.displayname -like "top*"} | ft displayname,userprincipalname,proxyaddresses




Search for users whom their UPN contains “TOP” in the start

get-msoluser -all | where-object {$_.userprincipalname -like "top*"} | ft displayname,userprincipalname,proxyaddresses



Office 365: Add additional accepted domain to SMTP Address

If you have configured Hybrid integration between Exchange 2010/2013 with Office 365 using dirSnyc or Azure active directory sync tool and then stopped the synchronization. The accepted domains and additional domains will be removed from the user’s Attributes on the cloud and in order to add these accepted domains again to all of the Office 365 users..

First we’ll have to connect to Exchange online with the following powershell tool. so Launch Azure powershell as Admin and copy the following line by line.

1- $UserCredential = Get-Credential

2- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

3- Import-PSSession $Session



First we’ll show/view user’s existing SMTP addresses, in order to do so we’ll use the following PowerShell cmdlet

For all users

4- Get-Mailbox | fl –property Alias, WindowsLiveID, EmailAddresses

For one user

Get-Mailbox –Identity | fl –property Alias, WindowsLiveID, EmailAddresses


Procedure to add an additional accepted domain to all users in the Office 365 tenant.


The domain must be verified on Office 365 first before applying those steps


$users = Get-Mailbox



foreach ($a in $users) {$a.emailaddresses.add("smtp:$($a.alias)")}




$users | %{Set-Mailbox $_.Identity -WindowsEmailAddress $_.WindowsEmailAddress}

Hope this helps Smile Tags: ,,