Handy 365 PowerShell Commands

Run all of these commands from PowerShell.

Connect to an Office 365 Tenant

Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session 

Enable/Disable Azure AD Sync Scheduler

Ran these commands if you want to stop or start Azure AD Sync from running per its schedule.

To disable:

Set-ADSyncScheduler -SyncCycleEnabled $false

To enable :

Set-ADSyncScheduler -SyncCycleEnabled $true

Start Azure AD Sync Cycle

Azure AD Sync is configured to sync changes from AD to Azure on a regular basis (every thirty minutes by default), but you can kick it of manually if you need to sync changes immediately.

Running it with delta syncs changes since the last sync:

Start-ADSyncSyncCycle -PolicyType Delta

Running without passing it a PolicyType also runs a delta sync:


Running it with a PolicyType of Initial syncs all objects and attributes within scope:

Start-ADSyncSyncCycle -PolicyType Initial

Give a Account Full Access to All Mailboxes in Office 365

Give a 365 user full access to all mailboxes, except for the “Admin” user. Change [email protected] to the user that you want to grant permissions to. The user that is granted access does not need to have license or mailbox.

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (Alias -ne 'Admin')} | Add-MailboxPermission -User [email protected] -AccessRights fullaccess -InheritanceType all

Empty 365 Recycle Bin

Run the following from PowerShell to connect to the 365 tenant:

Connect-MSOLService -Credential $cred

Run this to list deleted users to make sure there’s nothing that you want to keep.

Get-MsolUser –ReturnDeletedUsers

Run this to permanently delete everything from the Recycle Bin. There is no going back from this unless you restore from backup.

Get-MsolUser –ReturnDeletedUsers | Remove-MsolUser –RemoveFromRecycleBin -Force

Change a Mailbox Type

Use the following command to convert a mailbox to one of the four types: Regular, Room, Equipment or Shared. Replace the email address with the address of the mailbox you want to convert.

Get-Mailbox -Identity [email protected] | Set-Mailbox -Type Room

Get-MailboxFolderPermission [email protected]:\calendar –User Default

Leave a Reply

Your email address will not be published. Required fields are marked *