Using Exchange EWS to Obtain Exchange Online Meeting Details from Room Mailboxes



Exchange PFE Daya Patil shares with us a recent script she wrote to help obtain the meeting details from Exchange Online Room Mailboxes.


 

One of our customers needed a way to determine the number of meetings in each room mailbox Exchange online organization.  We quickly wrote a script to get this information, and wanted to share with the community to help those with similar requirements.

In the script, we determine the number of meetings from a given room mailbox. Script parameters can be changed according to your requirements.

Here is the script to count the number of meeting items and their details for a specific room mailbox using EWS. The script provides the CSV output for complete environment.

The script uses Exchange Web services managed API 2.0 with PowerShell, which you need to first download from the Microsoft download centre.

As always, treat this as sample code and you must fully test it in a non-production environment.

<# DISCLAIMER STARTS
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a #production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" #WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO #THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We #grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to</b>
 
reproduce and #distribute the object code form of the Sample Code, provided that You agree:(i) to not use Our name, #logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to #include a valid copyright notice on Your software product in which the Sample Code is embedded; and #(iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or #lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code." </b>
 
"This sample script is not supported under any Microsoft standard support program or service. The #sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied #warranties including, without limitation, any implied warranties of merchantability or of fitness for a #particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in #the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, #without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or #documentation, even if Microsoft has been advised of the possibility of such damages" </b>
 
DISCLAIMER ENDS #>
 
*********************
 
## Getting the user credentials
 
$credential = Get-Credential
 
$username = $credential.GetNetworkCredential().UserName
 
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($Credential.Password)
 
$Result = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
 
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
 
$creds = New-Object System.Net.NetworkCredential($username,$Result)
 
## Load Managed API dll
 
$EWSDLLPATH = "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll"
 
Import-module $EWSDLLPath
 
$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
 
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
 
$uri=[system.URI] "https://outlook.office365.com/EWS/Exchange.asmx"
 
$Service.Url = $uri
 
$service.Credentials = $creds
 
Clear-host
 
$RoomMailboxName = "room1@ContosoExOnline.onmicrosoft.com","Room2@ContosoExOnline.onmicrosoft.com"
 
$Result = @()
 
Foreach($Rmbx in $RoomMailboxName)
 
{
 
#Specifying start and end date to pull the data in that range
 
$StartDate = new-object System.DateTime(2017, 09, 01)
 
$EndDate = new-object System.DateTime(2017, 12, 31)
 
# Let’s Connect to the calendar folder. The list of all folders to which you can connect using EWS is available <a href="https://msdn.microsoft.com/en-us/library/office/dn535505(v=exchg.150).aspx">here</a>.
 
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$Rmbx)
 
$CalFolder = [Microsoft.Exchange.WebServices.Data.CalendarFolder]::Bind($service,$folderid)
 
# Setup Basic EWS Properties for Item Search
 
$cvCalview = new-object Microsoft.Exchange.WebServices.Data.CalendarView($StartDate,$EndDate,2000)
 
$cvCalview.PropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
 
$CalResult = $CalFolder.FindAppointments($cvCalview)
 
$ReqAttendees = $null
 
$OptAttendees = $null
 
$Resources = $null
 
foreach($SAppointment in $CalResult.Items)
 
{
 
$psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
 
$SAppointment.load($psPropset)
 
foreach($att in $SAppointment.RequiredAttendees)
 
{
 
$ReqAttendees = $ReqAttendees + $att.Address +", "
 
}
 
foreach($att in $SAppointment.OptionalAttendees)
 
{
 
$OptAttendees = $OptAttendees + $att.Address +", "
 
}
 
foreach($att in $SAppointment.Resources)
 
{
 
$Resources = $Resources + $att.Address +", "
 
}
 
$Result += [PSCustomObject]
 
@{
 
RoomMailbox = $Rmbx
 
Appointment_subject = $SAppointment.Subject.ToString()
 
IsRecurring = $SAppointment.IsRecurring.ToString()
 
Start_date = $SAppointment.Start.ToString()
 
End_date = $SAppointment.End.ToString()
 
Meeting_Organizer = $SAppointment.Organizer.Name.ToString()
 
RequiredAttendees = $ReqAttendees
 
OptionalAttendees =$OptAttendees
 
Resources = $Resources
 
}
 
}
 
}
 
#Export the output to CSV file
 
$Result |Export-Csv $PWD\RoomBooking-data.CSV –NoTypeInformation

 

 

Here is how the output would look like:

Sample Output

 


Posted by MSPFE Editor Rhoderick Milne


Comments (0)

Skip to main content