Using Exchange 2010 SP1. We are trying to delegate editor access to members of one group on members of another group and getting below error. Please advise.
ERROR
Exception calling "AddDelegates" with "3" argument(s): "The specified object was not found in the store"
At C:\Windows\System32\WindowsPowerShell\v1.0\ADTtmmailchecker.ps1:41 char 24
$service.AddDelegates <<<< ($mbMailbox, [Microsoft.Exchange.Webservices.Data.MeetingRequestsDeliveryScope\::DelegatesAndMe, $dgArray);
+CategoryInfo :NotSpecified: (:) [],MethodInvocationException
+FullyQualifiedErrorId :DotNetMethodException
#This powershell script retrieves ADT_TM security group members and add them as delegate with Editor right to the mailbox of any member of ADT_TM1 security group
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
$aceuser = [ADSI]$sidbind
Write-Host $aceuser.mail.ToString()
$service.AutodiscoverUrl("emailid")
$service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials("email","password")
#This powershell script retrieves ADT_TM security group members and add them as delegate with Editor right to the mailbox of any member of ADT_TM1 security group
foreach ($user in get-distributionGroupMember -identity "ADT_TM1")
{
$i = 0
$mbtoDelegate = $user.PrimarySmtpAddress
$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $mbtoDelegate);
$mbMailbox = new-object Microsoft.Exchange.WebServices.Data.Mailbox($mbtoDelegate)
$dgArray = new-object Microsoft.Exchange.WebServices.Data.DelegateUser[] 1
foreach ($user in get-distributionGroupMember -identity "ADT_TM1")
{
$delegatetoAdd = $user.PrimarySmtpAddress.ToString()
$dgUser = new-object Microsoft.Exchange.WebServices.Data.DelegateUser($delegatetoAdd)
$dgUser.ViewPrivateItems = $false
$dgUser.ReceiveCopiesOfMeetingMessages = $false
$dgUser.Permissions.CalendarFolderPermissionLevel = [Microsoft.Exchange.WebServices.Data.DelegateFolderPermissionLevel]::None
$dgUser.Permissions.InboxFolderPermissionLevel = [Microsoft.Exchange.WebServices.Data.DelegateFolderPermissionLevel]::Editor
$dgArray[0] = $dgUser
$service.AddDelegates($mbMailbox, [Microsoft.Exchange.WebServices.Data.MeetingRequestsDeliveryScope]::DelegatesAndMe, $dgArray);
}
}