Script Repository


Grant permissions on user's calendar to a specific user

October 02, 2018
1018

The folowing script grants permissions on the target user's calendar to a user specified in a property of the target user account.

Parameter:

  • $userDNProperty - Specifies the LDAP name of the property that stores the user who will gain permissions (e.g. assistant);
  • $accessRights - Specifies the permissions to be granted;
  • $exchangeServer - Specifies the fully qualified domain name of your Exchange Server.

Edit Remove
PowerShell
$userDNProperty = "assistant" # TODO: modify me
$accessRights = "Editor" # TODO: modify me
$exchangeServer = "exchangeServer.domain.com" # TODO: modify me

try
{
    $userDN = $Context.TargetObject.Get("assistant")
}
catch
{
    return
}

try
{
    # Create a remote PowerShell session to the Exchange Server
    $session = New-PSSession -configurationname Microsoft.Exchange -connectionURI http://$exchangeServer/PowerShell
    Import-PSSession $session -DisableNameChecking -AllowClobber
    
    # Get calendar folder name
    $calendarFolderName = (Get-MailboxFolderStatistics "%mail%" | where-object {$_.FolderType -eq "Calendar"}).Name
     
    # Set Mailbox Permissions
    try
    {
        Add-MailboxFolderPermission -Identity "%mail%:\$calendarFolderName" -User $userDN -AccessRights $accessRights -ErrorAction Stop
    }
    catch
    {
        $context.LogMessage("Could not set Calendar permissions for %username%'s mailbox. Error: " + $_.Exception.Message, "Error")
        return
    }
}
finally
{
    # Close the remote session and release resources
    Remove-PSSession $session
}

Comments ( 0 )
No results found.
Leave a comment