Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Using EWS to cancel a meeting in a room mailbox.

$
0
0

This seems like a common occurance at any company but there really doesn't seem to be a solution for it.  In Exchange people can reserve a conference room by inviting it to a meeting and with the proper setup the room mailbox will accept the meeting if the time slot is free.  The problem comes in when the organizer of the meeting leaves the company.  I'm working on a project using Exchange Web Services to clean out our room mailboxes of meetings which were scheduled by people who are no longer at the company.  The only way I know how is through web services and through an account that has been given the impersonation right (which I am using).

The problem I'm having is that through web services there is a method on an appointment item called CancelMeeting which would do just this except I'm getting the below error:

Exception calling "CancelMeeting" with "0" argument(s): "User must be an organizer for CancelCalendarItem action."

I'm looking for any suggestions as I've been looking out over the Internet for quite a bit now and not really coming up with anything of use.  Below is the code I'm using (cleaned up to remove company information).  Any thoughts or input that could be helpful would be much appreciated.

#Address of object to connect to
$roomAddress = 'room@contoso.com'

#Path to the EWS DLL
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"

#Load the EWS DLL
[void][Reflection.Assembly]::LoadFile($dllpath)
	
#Create a service object that supports Exchange 2010 SP1
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
	
#Store the passed in credential
#$service.Credentials = $credential

#Web services url
$uri=[system.URI] "https://ExhcangeServer.Contoso.com/EWS/Exchange.asmx"
$service.Url = $uri
#The impersonation details.
$ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId
$ImpersonatedUserId.IdType = 'smtpaddress'
$ImpersonatedUserId.Id = $roomAddress
$service.ImpersonatedUserId = $ImpersonatedUserId
#Build a folder ID object
$folderid = new-object  Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$roomAddress)
#Bind to the mailbox and folder.
$CalendarFolder = [Microsoft.Exchange.WebServices.Data.CalendarFolder]::Bind($service,$folderid)
#Get up to 2000 entries from the folder and find any that are appointments from today and the next 5 days.
$startDAte = get-date
$endDate = (get-date).AddDays(+5)
$cvCalendarview = new-object Microsoft.Exchange.WebServices.Data.CalendarView($StartDate,$EndDate,2000)
$frCalendarResult = $CalendarFolder.FindAppointments($cvCalendarview)
#Build a view
$psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text

#Cancel the first meeting found (there is one here)
$frCalendarResult.Items[0].CancelMeeting()



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>