-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEMSAPI-UpdateXenegradeListFromEMSDatabase.ps1
119 lines (86 loc) · 4.55 KB
/
EMSAPI-UpdateXenegradeListFromEMSDatabase.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
## One Time Use Program to Download all of the existing rooms from EMS and match them up against Continuing Ed's Xenegrade spreadsheet.
## Add in Missing Rooms and their EMS ID Number/Room Name, but also put the EMS ID Number/Room Name on rooms that already exist in the Xenegrade sheet.
Clear-Host
## EMS API Connection Variables
$url = "http://ems.yourdomain.com/EMSAPI/Service.asmx"
$username = "youremsapiuser"
$password = "youremsapipassword"
## User Changeable Items
$xenegradeincomingfilename = "C:\Users\shardwic\Desktop\EMS\LSUS-Rooms-Xenegrade.csv"
$xenegradeoutgoingfilename = "C:\Users\shardwic\Desktop\EMS\LSUS-Rooms-Xenegrade-corrected2.csv"
$global:searchstartdate = "1/1/2018" #Earliest potential date - used in searching to see if has already been booked
$global:searchenddate = "12/31/2018" #Last potential date - used in searching to see if has already been booked
## Constants
$global:allBuildings = -1 # Building Code -1 is ALL buildings
$EmsConnector = New-WebServiceProxy -Uri $url
[xml]$ApiVersion = $EmsConnector.GetAPIVersion()
Write-Host "EMS Version" $ApiVersion.API.APIVersion.Version $ApiVersion.API.APIVersion.License
Write-Host ""
## Store in Arrays these items that are needed for browsing Bookings
[xml]$Statuses = $EmsConnector.GetStatuses($username, $password)
$StatusArray = $Statuses.Statuses.Data.id
[xml]$EventTypes=$EmsConnector.GetEventTypes($username, $password)
$EventTypeArray = $EventTypes.EventTypes.Data.id
[xml]$GroupTypes = $EmsConnector.GetGroupTypes($username, $password)
$GroupArray = $GroupTypes.GroupTypes.Data.id
# Store in Array this item to be able to use as a room lookup
[xml]$AllRooms = $EmsConnector.GetAllRooms($username, $password, $allbuildings)
$global:RoomTranslation = $AllRooms.Rooms.Data | Select-Object -Property Id, Room, Description, Building
## Class File Import
$XenegradeHeader = "EMSRoomID","EMSRoomCode","rooID","rooRoom","facID","facName","buiID","buiName","Location"
$XenegradeFile = Import-CSV -Path $xenegradeincomingfilename -Header $xenegradeHeader
$XenegradeCorrected = @()
$RoomTranslation | ForEach-Object {
$CurrentID = $_.Id
$CurrentRoom = $_.Room
$CurrentDesc = $_.Description
$CurrentBldg = $_.Building
$CurrentBldgNumber = $null
if ($CurrentDesc.StartsWith("SC")) { $CurrentDesc = $CurrentDesc.Replace("SC", "Science Building,")
$CurrentBldgNumber = "9"
}
if ($CurrentDesc.StartsWith("TC")) { $CurrentDesc = $CurrentDesc.Replace("TC", "Technology Center,")
$CurrentBldgNumber = "2"
}
if ($CurrentDesc.StartsWith("BH")) { $CurrentDesc = $CurrentDesc.Replace("BH", "Bronson Hall,")
$CurrentBldgNumber = "3"
}
if ($CurrentDesc.StartsWith("NL")) { $CurrentDesc = $CurrentDesc.Replace("NL", "Noel Library,") }
if ($CurrentDesc.StartsWith("BE")) { $CurrentDesc = $CurrentDesc.Replace("BE", "Business Education,")
$CurrentBldgNumber = "4"
}
$XenObject = $XenegradeFile | Where-Object {$_.EMSRoomCode -eq $CurrentRoom}
if ($XenObject -ne $null) {
#Write-Host $CurrentRoom "is in the xenegrade file. Add the code $CurrentID"
$RoomProperties = [pscustomobject]@{
EMSRoomID = $CurrentID
EMSRoomCode = $CurrentRoom
rooID = $XenObject.rooID
rooRoom = $XenObject.RooRoom
facID = $XenObject.FacId
facName = $XenObject.FacName
buiID = $XenObject.BuiID
buiName = $XenObject.BuiName
Location = $XenObject.Location
}
$XenegradeCorrected += $RoomProperties
}
else {
#Write-Host $CurrentRoom "IS MISSING FROM XENEGRADE FILE. Add Record with Code $CurrentID"
$RoomProperties = [pscustomobject]@{
EMSRoomID = $CurrentID
EMSRoomCode = $CurrentRoom
rooID = $null
rooRoom = $null
facID = "27"
facName = "LSU Shreveport"
buiID = $CurrentBldgNumber
buiName = $CurrentBldg
Location = ("LSU Shreveport, " + $CurrentDesc)
}
$XenegradeCorrected += $RoomProperties
}
}
$xenegradecorrected | Format-Table -Property EMSRoomID, EMSRoomCode, rooId, rooRoom, Location, buiID
$XenegradeCorrected | Export-Csv -Path $xenegradeoutgoingfilename