Snippets of PowerShell commands to make your Office 365 administration experience more enjoyable.

Connect to Office 365: $user = “@" $cred = Get-Credential -Credential $user Import-Module MSOnline Connect-MsolService -Credential $cred </em>

List all licensed users: Get-MsolUser -all | where {$_.isLicensed -eq $TRUE}

Show all disconnected users: Get-MsolUser -returndeletedusers

**A hard delete of a disconnected mailbox: **Remove-MsolUser -RemoveFromRecycleBin -UserPrincipalName user@domain.tld

**A hard delete of all disconnected users: **Get-MsolUser -returndeleteduser -all | Remove-MsolUser -removefromrecyclebin -force

Set immutableID to match new user GUID: $cn = “" $guid = (get-aduser -f {cn -eq $cn} -pr objectguid).objectguid $upn- = (get-aduser -f {cn -eq $cn}).userprincipalname $ImmutableID = [System.Convert]::ToBase64String($guid.ToByteArray())

set-msolUser -userprincipalname $upn -immutableID $ImmutableID

**Set immutableID to match new NULL (Allows SMTP macthing to connect mailbox): **set-msolUser -userprincipalname -immutableID $NULL