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 RemoteSignedThis 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-CredentialGet-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 https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirectionHere'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 $SessionThis 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 email@example.com:\calendar -user firstname.lastname@example.org -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 email@example.com:\calendar -user firstname.lastname@example.org 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 $SessionThis will end the connection to the O365 environment.