Jump to content

Recommended Posts

Posted (edited)

#region Script Header
<#
   Script that connects to O365 Room Calendars and gets the events from the calendar for the specified number of days
   Auth - HAP12
#>
#endregion

#region Rest API
<# 
   O365 Rest API connection to access a Room calendar - the /users/meetingroom1.yourdomain.com part needs updating for the Room calendar that you are connecting to. 
   Could be scripted to connect to all the Room calendars using the commented line below (get-mailbox....)
   The startDateTime=$(Get-Date)&endDateTime=$((Get-Date).AddDays(7)) could be passed via a var - default is to get TODAY and add 7 days.
   The Foreach could do with beging a var that represents the name of the room that is being exported.
#>

Invoke-RestMethod `
   -Uri "https://outlook.office365.com/api/v1.0/users/meetingroom1.yourdomain.com/calendarview?startDateTime=$(Get-Date)&endDateTime=$((Get-Date).AddDays(7))"`
   -Credential (Get-Credential) |
   foreach-object{ $_.Value } -OutVariable phfmr1evts
   
   #Get-Mailbox -ResultSize unlimited -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select Name,Alias

#endregion

#region Functions
#region Get-CalEventData
<#
   creates the object to receive each event in the loop - if more properties are required from the raw data add additional params to handle the data required.   
#>

function Event-Data()
{
 param ($organizerName, $organizerAddress, $location, $subject, $startTime, $endTime, $eventIsAllDay, $eventImportance)

 $eventData = new-object PSObject

 $eventData | add-member -type NoteProperty -Name OrganizerName -Value $organizerName
 $eventData | add-member -type NoteProperty -Name OrganizerAddress -Value $organizerAddress
 $eventData | add-member -type NoteProperty -Name Location -Value $location
 $eventData | add-member -type NoteProperty -Name Subject -Value $subject
 $eventData | add-member -type NoteProperty -Name StartTime -Value $startTime
 $eventData | add-member -type NoteProperty -Name EndTime -Value $endTime
 $eventData | add-member -type NoteProperty -Name AllDayEvent -Value $eventIsAllDay
 $eventData | add-member -type NoteProperty -Name EventImportance -Value $eventImportance

 return $eventData
}
#endregion
#endregion

#region THE BIT THAT DOES THE WORK!

<#
  The foreach loop grabs each event from the var created when we gathered the events via the API above, this iterates through the events and pulls out the details that we are
  interested in, the function above is then called and each event is exported out to the CSV specified at the end of the Get-CalEventData line below.  This needs changing to a
  var and should probably represent the calendar name.
#>

   foreach($event in $phfmr1evts){
     
       $organizerName = $event.Organizer.EmailAddress.Name
       $organizerAddress = $event.Organizer.EmailAddress.Address
       $location = $event.Location.DisplayName
       $subject = $event.Subject
       $startTime = $event.Start
       $endTime = $event.End
       $eventIsAllDay = $event.IsAllDay
       $eventImportance = $event.Importance

       Get-CalEventData -organizerName $organizerName -organizerAddress $organizerAddress -location $location -subject $subject -startTime $startTime -endTime $endTime -eventIsAllDay $eventIsAllDay -eventImportance $eventImportance | Export-Csv -Path C:\localapp\meetingroom1.csv -NoTypeInformation -Append
   }
#endregion

 

Woking on event data from room calendars the above connects to a calendar, get the events in the calendar and outputs them to a CSV

Edited by HPlum78
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...