My goal for this powershell script is to monitor a particular folder for all the mailboxes in Exchange Online (Office 365) and if an item is created, it will send that item as an email to another smtp address. I can achieve this for just one mailbox without any errors using impersonation.
However, I am trying to create a list of folderid array for each mailbox like:
foreach ($usermailbox in $mboxlist) {
$farray += Get-TargetF($usermailbox)
}
$farray contains objects of the type:
Microsoft.Exchange.WebServices.Data.FolderId($tfTargetFolder.Id)
I then look for events in:
$service.SubscribeToPullNotifications($farray,60,$null,[Microsoft.Exchange.WebServices.Data.EventType]::Created)
Note that Get-TargetF function gets the servername through autodiscover for each mailbox.
It also uses $service.FindFolders
for finding the correct folder.
Running the script like I showed above results in an error for few mailboxes but not all (I had filtered out 5 mailboxes for testing).
New-Object : Constructor not found. Cannot find an appropriate constructor for type Microsoft.Exchange.WebServices.Data.FolderId.
At C:\Documents\mysc.ps1:63 char:22
+ $InboxId = new-object <<<< Microsoft.Exchange.WebServices.Data.FolderId($tfTargetFolder.Id)
+ CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand
And when I start listening to the events, I get this error:
Cannot find an overload for "SubscribeToPullNotifications" and the argument count: "4".
At C:\Documents\mysc.ps1:79 char:59
+ $pullSubscription = $service.SubscribeToPullNotifications <<<< ($farray,60,$null,[Microsoft.Exchange.WebServices.Data.EventType]::Created)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
I have also not figured out how to deal with the throttling issues with EWS on Exchange Online mentioned here. I suspect the subscription above will timeout after an hour by default.
What is the correct way to achieve this in a single pssession?