42 lines
1.5 KiB
PowerShell
42 lines
1.5 KiB
PowerShell
# 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
|