[Outlook] Use powershell to do delegates like outlook.

Environment: Exchange 2010 SP2 + Outlook 2010

Adding delegate is actually not that easy i thought, at least not just one command to complete everything, this is because many additional actions will be performed by outlook client, command on server actually is one of them.

Welcome email to: [email protected]

Below is a typical settings screenshot from outlook 2010, you can see i highlighted those permission items.

1. Editor permission of Calendar

2. Editor permission of Tasks

3. "Delegate receives copies of meeting-related messages sent to me" will be ticked

Things already like this on old outlook 2003 client, but the additional permissions/options complete by outlook cause a problem, we need to do mutliple steps from server with many commands.

In Exchange 2010, the cmdlet Set-Mailbox -GrantSendOnBehalfTo can be used to grant delegate, Add-MailboxFolderPermission cmdlet can be used to grant folder permissions like Calendar and Tasks. Problem is on the option "Delegate receives copies of meeting-related messages sent to me", there is no directly cmdlet can enable this option, anyhow this option is quite necessaried by assistants.

To solve the problem, since normal cmdlets can't be used, EWS (Exchagne web service) is needed, actually outlook is also use EWS to do the same.

First, we need download EWS API from Microsoft.

EWS API - http://www.microsoft.com/en-us/download/details.aspx?id=35371

You can choose to install or just extract what we need from the installer with 7-zip instead, all we need is "Microsoft.Exchange.WebServices.dll".

Open the powershell, use import-module to import the binary dll, so the classes can be used by us, of course [Reflection.Assembly]::LoadFile() can do the same.

Import-Module .\Microsoft.Exchange.WebServices.dll

Below command create a ExchangeService instance from the class, if don't specify exchange version, the instance will use the latest version in API by default.

$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService('Exchange2010_SP2')

User $Service can show some properties, method can be retrieved by get-member cmdlet, too many of them i won't paste here.

Now, we need to specify the URL of EWS, or use Autodiscover function of Exchange, i recommand Autodiscover function, because it reads settings of autodiscover directly from Active Directory, as long as outlook works fine, the function must running well too.

$Service.AutodiscoverUrl('[email protected]')

Or, specify EWS url like below

$Service.Url = 'https://CASServer/ews/exchange.asmx'

Dategates related methods can be known from $Service | Get-Member

AddDelegates
GetDelegates
RemoveDelegates
UpdateDelegates

Obviously, AddDalegates is the one, $Service.AddDelegates can output its paramembers,

Parameter 1 is a mailbox, which is the target mailbox
Microsoft.Exchange.WebServices.Data.Mailbox mailbox

Parameter 2 is a meetingRequestsDeliveryScope
Microsoft.Exchange.WebServices.Data.MeetingRequestsDeliveryScope meetingRequestsDeliveryScope

Parameter 3 is a delegateUsers collection
Microsoft.Exchange.WebServices.Data.DelegateUser

Parameter 2, you can see it from below outlook screenshot,

Now we have method, parameters, including parameter types, generate them now.

Parameter 1,

$Mailbox = New-Object Microsoft.Exchange.WebServices.Data.Mailbox('[email protected]')

Parameter 2,

$Scope = [Microsoft.Exchange.WebServices.Data.MeetingRequestsDeliveryScope]::DelegatesOnly

Parameter 3,

$dgUser = New-Object Microsoft.Exchange.WebServices.Data.DelegateUser('zzz@yyy.com')
$dgUser.Permissions.CalendarFolderPermissionLevel = 'editor'
$dgUser.Permissions.TasksFolderPermissionLevel = 'editor'
$dgUser.ReceiveCopiesOfMeetingMessages = $true

All right, parameters filled, use AddDelegates method to apply it.

$Service.AddDelegates($Mailbox, $Scope, $dgUser)

There will be no errors if every step runs well, the method will return running result, even if failed we can still know why failure.

At last, and most artical missed is you must have at least impersonation role,

http://msdn.microsoft.com/en-us/library/office/bb204095(v=exchg.140).aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章