Files
Scripting/Powershell/PowerShell-Office365Admin/Exchange/GrantCalendarDelegateAccess.ps1
DistractADD cfddd4fad2 Added Files
2021-07-06 13:16:46 +10:00

42 lines
1.5 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Script to grant access rights on mailboxes
#
# Mailboxes to grant rights on
$grantRightsOnMailboxes = @('','')
# Users to grant rights to
$grantRightsToUsers = @('','')
# Rights to grant
$accessRights = 'Editor'
# Establish a session to Exchange Online
$credentials = Get-Credential -Message 'Enter your Exchange Online administrator credentials'
$connectionParams = @{
'ConfigurationName' = 'Microsoft.Exchange';
'ConnectionUri' = 'https://outlook.office365.com/powershell-liveid/';
'Credential' = $credentials;
'Authentication' = 'Basic';
'AllowRedirection' = $true
}
$exchangeSession = New-PSSession @connectionParams
Import-PSSession -Session $exchangeSession
# Apply the permissions
foreach ($grantRightsToUser in $grantRightsToUsers ) {
foreach ($grantRightsOnMailbox in $grantRightsOnMailboxes) {
$calendarIdentity = $grantRightsOnMailbox + ':\Calendar'
$existingPermissions = Get-MailboxFolderPermission -Identity $calendarIdentity -User $grantRightsToUser -ErrorAction SilentlyContinue
if (!($existingPermissions)) {
Add-MailboxFolderPermission -Identity $calendarIdentity -User $grantRightsToUser -AccessRights $accessRights
}
else {
Set-MailboxFolderPermission -Identity $calendarIdentity -User $grantRightsToUser -AccessRights $accessRights
}
Set-Mailbox -Identity $upn GrantSendOnBehalfTo @{add=$editor}
}
}
# End the PowerShell session
Remove-PSSession -Session $exchangeSession