码迷,mamicode.com
首页 > 系统相关 > 详细

[Outlook] Use powershell to do delegates like outlook.

时间:2014-10-30 15:15:58      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   ar   for   sp   div   on   

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.

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

bubuko.com,布布扣

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".

bubuko.com,布布扣

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(‘xxxxx@yyy.com‘)

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,

bubuko.com,布布扣

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

Parameter 1,

$Mailbox = New-Object Microsoft.Exchange.WebServices.Data.Mailbox(‘xxxxx@yyy.com‘)

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.

[Outlook] Use powershell to do delegates like outlook.

标签:blog   http   io   os   ar   for   sp   div   on   

原文地址:http://www.cnblogs.com/LarryAtCNBlog/p/4062593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!