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  >
article

KB-4906: Helpful PowerShell commands for Office 365

Centrify Identity Service, App Edition ,  

10 February,17 at 08:34 PM

Applies to: Centrify Identity Service with Office 365

Question:

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


Answer:

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: @domain.onmicrosoft.com
  2. Then run the command again to set to the desired domain:
  • Set-MsolUserPrincipalName -UserPrincipalName bob.oldman@contoso.onmicrosoft.com -NewUserPrincipalName bob.newman@contoso.com


See also:

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