Adding and Removing Calendar Permissions in Office 365 with PowerShell

Right then! More PowerShell shenanigans and this one is more by necessity rather than simply ‘doing it because you can’ as (correct me if I’m wrong) there’s no way to do this in the GUI/Admin Center.

So, nice and simple really this one. As before in the last post, you’ll need to connect to your Office365 environment first before typing any commands and you can do this by running the following lines of code:

> Set-ExecutionPolicy RemoteSigned
This sets the script-running policy of your machine to allow scripts to be ran, but they need to be signed by a trusted publisher. The default is "Restricted" which means scripts will not run.

> $UserCredential = Get-Credential
Get-Credential will pop up a window asking for a username and password. The value of what you type into the credential window will the be stored into the $UserCredential variable for later use.

> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection 
Here's the real meat of the operation. This will create a new PowerShell session to Office365 using the credentials contained within $UserCredential which we defined earlier. The whole lot will then be wrapped into a variable called $session.

> Import-PSSession $Session
This imports the remote session you have just created into your local session for modification.

So, with that out the way we just need to run the last little bit.

> Add-MailboxFolderPermission -Identity\calendar -user -AccessRights Editor
This adds USER2 to the permission set for USER1 with the access rights of editor.

And to remove (somewhat obviously)

> Remove-MailboxFolderPermission -Identity\calendar -user
This removes USER2 to the permission set for USER1 (without the access level tag)

That’s it! Then end your session by running the following command:

> Remove-PSSession $Session
This will end the connection to the O365 environment.

All done!


30-something Sysadmin from the Midlands, UK.