Useful PowerShell Commands for Office 365 Administration


Get-MsolUser -UserPrincipalName xxxx


Get-Group -Identity xxxx

Get-DistributionGroup -Identity xxxx

Remove-UnifiedGroup -Identity

Set-DistributionGroup –Identity -AcceptMessagesOnlyFromSendersOrMembers((Get-DistributionGroup -identity + ““)

Set-DistributionGroup -Identity -RequireSenderAuthenticationEnabled $true

Azure AD Sync


Set-MsolDirSyncEnabled –EnableDirSync $true

Set-MsolDirSyncEnabled –EnableDirSync $false

To run form domain controller where ADSync is installed:

Start-ADSyncSyncCycle -PolicyType delta

Start-ADSyncSyncCycle -PolicyType initial




Get-MailboxPermission | where {$_.isInherited -eq $false}

Get-RecipientPermission -Identity

Get-Mailbox -SoftDeletedMailbox -ResultSize Unlimited

By |2018-05-28T11:22:04+00:00May 15th, 2018|Office 365, Powershell|0 Comments

Delete an object from Azure AD synced from On Premise

Sometimes we need to delete an object from Azure AD which is synced with the local AD but despite moving the object (user, group or a contact) to a non-synced OU, which is technically equivalent to asking Azure AD to delete the object, the deletion does not take place. As the objects are synced from local AD so we cannot delete the object directly using the Office Admin portal

So one of the obvious choice in this particular case is to stop the sync from local AD to Azure AD. We can stop the sync using this command

Set-MsolDirSyncEnabled –EnableDirSync $false

Although it can take up to 72 hours as per Microsoft documentation, but usually it takes less. In my case I disabled sync before leaving from work around 5 pm in the evening and next morning at 9 am I was able to delete the object using the Office Admin portal. Once that is done we can re-enable the sync.

Set-MsolDirSyncEnabled –EnableDirSync $true

To check the status of the sync this command is used:












By |2018-05-15T08:30:22+00:00May 15th, 2018|Uncategorized|0 Comments

Exchange Online Error: The user’s on-premises mailbox hasn’t been migrated

Recently I came across this error when trying to provision a new mailbox for a user. The user was synced to Azure AD in the past and most probably his mailbox was migrated too. But then as the account was not active, it was deactivated and as the deactived accounts OU was not enabled for sync, the user mailbox got soft deleted and eventually after a month’s grace period got hard deleted. Now that the user was brought to active users OU which was enabled for sync, the mailbox was not getting created depsite assigning the Exchange license.

Users OnPremises Mailbox Not Migrated







Error: The user’s on-premises mailbox hasn’t been migrated

The Exchange License was unassigned and re-assigned just to make sure the problem is not coming from there but it did not resolve the issue.

Office 365 License Assigned



















Exchange License Assigned

While searching online I came across a few posts referring to the AD attributes particularly the msexchmailboxguid attribute. In the presence of this attribute Exchange Online thinks that the user has already a mailbox in the Exchange On-Premise so it does not create a fresh mailbox.

















msexchmailboxguid Attribute

In order to create a fresh mailbox we need to clear this attribute. Once the attribute is cleared and user re-synced, Exchange Online provisions a new mailbox for the user. I do not remember exactly if it is absolutely necessary to clear the following other attributes as well but in my case I cleared the following as well:

msExchRecipientDisplayType: -2147483642

msExchRecipientTypeDetails: 2147483648

msExchRemoteRecipientType: 4

By |2018-03-15T09:22:18+00:00March 14th, 2018|EXOL|0 Comments