Tips for finding Knowledge Articles

  • - Enter just a few key words related to your question or problem
  • - Add Key words to refine your search as necessary
  • - Do not use punctuation
  • - Search is not case sensitive
  • - Avoid non-descriptive filler words like "how", "the", "what", etc.
  • - If you do not find what you are looking for the first time,reduce the number of key words you enter and try searching again.
  • - Minimum supported Internet Explorer version is IE9
Home  >

KB-4906: Helpful PowerShell commands for Office 365

App Access Service ,  

10 February,17 at 08:34 PM

Applies to: Centrify Identity Service with Office 365


Is there a reference of useful PowerShell commands that can be used with Office 365?


Below are a list of PowerShell commands that have proven to come in handy when working with O365. 

These commands need the Microsoft Azure Active Directory Module for Windows PowerShell installed, and administrator credentials into O365.

Retrieve Admin Credentials for O365:
  • $msolcred = Get-Credential

Connect to O365:
  • Connect-MsolService -credential $msolcred

Force remove O365 Accounts
  • Get-MsolUser -all | Where-Object {$_.isLicensed -ne “false"} | Remove-MsolUser -Force 
  • Get-MsolUser -all | Where-Object {$_.isLicensed -eq “true"} | Remove-MsolUser -Force

Empty the Trash bin
  • Get-MsolUser -all -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force

Force remove O365 Groups 
  • Get-MsolGroup -SearchString "MyGroup" | Remove-MsolGroup 
Force change UPN 
  1. First set the UPN to the default O365 domain:
  2. Then run the command again to set to the desired domain:
  • Set-MsolUserPrincipalName -UserPrincipalName -NewUserPrincipalName

See also:

Still have questions? Click here to log a technical support case, or collaborate with your peers in Centrify's Online Community.