We have been working on Office 365 migrations quite long and found Azure PowerShell more than useful in managing 365 hosted organizations. There are a lot of cmdlet which we use regularly and believe every Office 365 Admin should know about them. Hence I am summarizing this article detailing all of them.

To execute following Cmdlets , you need to install and connect to windows Azure PowerShell console,  Refer following article to understand how to do that.

How to Connect to Office 365 via PowerShell

Get company information


Find out total number of users in your office 365 Organization.

(Get-MsolUser -All).length

Get the total number of deleted users in your Office365 Org

(get-msoluser -returndeletedusers).length

Get a complete dump of all the users in your Office 365 Org.

Get-MsolUser -All

Get List of all the Groups in your Office 365 Org.

Get-MsolGroup -All

Provide the details of one particular user name

Get-MsolUser -UserPrincipalName $myusername | Format-List

Provides a dump of all users with UsageLocation US

Get-MsolUser -UsageLocation “US”


Specify  Usage location ( Country where user is going to be mostly working like US or India) before activating it.

Set-MSOLUser –UserPrincipalName $myusername –UsageLocation US


How to set Password Never Expire for Office 365 users.

Set-MsolUser -UserPrincipalName $myusername -PasswordNeverExpires $true


Find Users with certain UPN or replace with other attribute or logic

Get-MsolUser | where {$_.UserPrincipalName -match “contoso.com”}

Get-MsolUser | where {$_.UsageLocation -match “UK”} | Format-Table DisplayName, UserPrincipalName, UsageLocation

Get-MsolUser | where {$_.UserPrincipalName -match “John”} | Format-Table DisplayName, UserPrincipalName, UsageLocation

Set User attributes using Set-MsolUser Cmdlet

Set-MsolUser -UserPrincipalName $myusername -Title  “Dr.”

Similarly Get-msoluser can provide dump of all MS online related user attributes

Get-MsolUser -UserPrincipalName $myusername |Format-list DisplayName, Title

Get Total number users synced with Directory Syncronization

$synceduser = Get-MsolUser -All | where {$_.LastDirSyncTime.Year -ge 2014}



How to Delete a user account and to remove it from recycle bin in Office 365

remove-msoluser -userprincipalname username@tenant.onmicrosoft.com

remove-msoluser -userprincipalname username@tenant.onmicrosoft.com -removefromrecyclebin

How to Change Office 365 User’s UserPrincipalName

Set-MsolUserPrincipalName -UserPrincipalName username@tenant.onmicrosoft.com -NewUserPrincipalName username@domain.com

Count the total number of objects in your Office 365 Org

$Countobjects = (Get-MsolUser -All).length + (get-msoluser -returndeletedusers).length + (Get-MsolGroup -All).length + (Get-MsolContact -All).length


Managing MSonline Groups

Get-MsolGroup -All

New-MsolGroup -DisplayName “Group1”

Delete all Groups

get-msolgroup -all | foreach { Remove-Msolgroup -ObjectId $_.ObjectId -force }

Managing Contacts

Get-MsolContact -All

Delete all contacts

get-msolcontact -all | foreach { Remove-Msolcontact -ObjectId $_.ObjectId -force }

Get All Unlicensed users

Get-MsolUser -UnlicensedUsersOnly -All | Ft UserPrincipalName

All these commands I shared here, are just the tip of the iceberg but these are few things which you need mostly for managing your Office 365 Org.

The following two tabs change content below.
An automobile enthusiast at heart and computer geek by profession, started my Career with MS in 2005.Left Jobs and started Pledge Technologies (the parent company to Grishbi) back in 2009.We have been providing IT consulting to various Small and Medium businesses across US and UK since then.Our company specialises in Microsoft Server technologies like AD, Exchange, the rest and with numerous Office 365 migrations under our belt, we quite an expert with that too. Whatever we learn in our day to day life, we share it back on Grishbi as a Thank for all the love and support our customers have given us.
%d bloggers like this: