Created
September 21, 2017 13:47
-
-
Save jdmills-edu/6b8492ce34081eb31ed824c69af11dd9 to your computer and use it in GitHub Desktop.
A PowerShell script that uses the Dean Evans EMS API to return the list of bookings in a given room at a given time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$building, | |
[string]$room, | |
[string]$time | |
) | |
$dateTime = $time | Get-Date | |
$dateString = $dateTime.ToString("yyyy-MM-ddThh:mm:ss") | |
#Define API connection parameters | |
$url = "http://ems.yourdomain.com/emsapi/service.asmx" | |
$apiuser = "youremsapiuser" | |
$apipw = "youremsapipassword" | |
#Define API endpoints | |
$endpoint_buildings = "/GetBuildings" | |
$uri_buildings = $url+$endpoint_buildings | |
$endpoint_rooms = "/GetAllRooms" | |
$uri_rooms = $url+$endpoint_rooms | |
$endpoint_bookings = "/GetAllRoomBookings" | |
$uri_bookings = $url+$endpoint_bookings | |
#Get Buildings | |
$query_buildings = " | |
UserName=$apiuser | |
Password=$apipw | |
" | |
$urlencode_buildings = $query_buildings.Trim() -replace("`r`n","&") -replace(" ") | |
$buildings_wr = Invoke-RestMethod -Uri $uri_buildings -Method Post -Body $urlencode_buildings | |
$buildings = ($buildings_wr.string.'#text' | ConvertFrom-Json).data | |
$thisBuilding = $buildings | where BuildingCode -like "*$building*" | |
$buildingID = $thisBuilding.ID | |
$query_rooms = " | |
UserName=$apiuser | |
Password=$apipw | |
BuildingID=$buildingID | |
" | |
$urlencode_rooms = $query_rooms.Trim() -replace("`r`n","&") -replace(" ") | |
$rooms_wr = Invoke-RestMethod -Uri $uri_rooms -Method Post -Body $urlencode_rooms | |
$rooms = ($rooms_wr.string.'#text' | ConvertFrom-Json).data | |
$thisRoom = $rooms | Where-Object{$_.Room.split("-")[1] -like "*$room*"} | |
$roomID = $thisRoom.ID | |
$query_bookings = " | |
UserName=$apiuser | |
Password=$apipw | |
StartDate=$dateString | |
EndDate=$dateString | |
RoomID=$roomID | |
ViewComboRoomComponents=false | |
" | |
#URL encode bookings query. | |
$urlencode_bookings = $query_bookings.Trim() -replace("`r`n","&") -replace(" ") | |
$bookings_wr = Invoke-RestMethod -Uri $uri_bookings -Method Post -Body $urlencode_bookings | |
$bookings = ($bookings_wr.string.'#text' | ConvertFrom-Json).data | |
$booking = $bookings | Where-Object{$dateTime -gt $_.TimeEventStart -and $dateTime -lt $_.TimeEventEnd} | |
return $booking |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JD,
Thanks for sharing ;-)
Here is a different take on this using the New-WebServiceProxy cmdlet.