Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ApiRoot = "https://api.samanage.com"
- $ApiIncidents = "https://api.samanage.com/incidents"
- $ApiGroup = "https://api.samanage.com/groups"
- $Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
- $Headers.Add("Accept", 'application/vnd.samanage.v2.1+json')
- $Headers.Add("X-Samanage-Authorization", 'Bearer BunchOfSecretStuff')
- $ContentType = "application/json"
- $Incident = Read-Host "Enter Incident ID"
- $Incident = $Incident + ".json"
- $URI = "$ApiIncidents/$Incident" + "?layout=long"
- $SAM_Results = $(Invoke-WebRequest -Header $Headers -ContentType $ContentType -Method Get -UseBasicParsing -URI $URI).Content | ConvertFrom-Json
- $Final_Results = $SAM_Results.request_variables | Select Name,Type,Value
- $Count = $Final_Results.Count
- $Type_Var = "Type of Request"
- $Room_Var = "Room Name"
- $Seating_Var = "New Seating Capacity"
- $Equipment_Var = "Equipment in the Conference Room"
- $Building_Var ="Building"
- $LocationDescription_Var = "Location Description"
- $RequestDate_Var = "Requested Date of Change"
- $Restricted_Var = "Restricted Use (Approval Required)"
- $Access_Var = "Who Needs Access to the Room (Required for Restricted Access Only)"
- $Samanage_Array = @($Type_Var,$Room_Var,$Seating_Var,$Equipment_Var,$Building_Var,$LocationDescription_Var,$RequestDate_Var,$Restricted_Var,$Access_Var)
- $Results_Array = @()
- $Equipment_Array = @()
- $Var_Count = $Samanage_Array.Length
- for ($g = 0; $g -lt $Var_Count ; $g++) {
- for ($j = 0; $j -lt $Count ; $j++) {
- if ($Final_Results.name[$j] -eq $Samanage_Array[$g]) {
- Write-Host "Key $j is:" $Final_Results.name[$j]
- $Results_Array += $Final_Results.value[$j]
- Write-Host "Value $j is:" $Final_Results.value[$j]
- Write-Host ""
- }
- }
- }
- if ($Debug ='1') {
- Write-Host '$Samanage_Array count is:' $Samanage_Array.Length
- }
- Write-Host ""
- pause
- Various Output: All values shifted down by one because Key 3 contains 2 Values, AppleTV and TV.
- Key 0 is: Type of Request
- Value 0 is: Add
- Key 1 is: Room Name
- Value 1 is: Test Conference Room
- Key 2 is: New Seating Capacity
- Value 2 is: 10
- Key 3 is: Equipment in the Conference Room
- Value 3 is: Apple TV
- Key 4 is: Building
- Value 4 is: TV
- Key 5 is: Location Description
- Value 5 is: Main Building
- Key 6 is: Requested Date of Change
- Value 6 is: A Room in a Building
- Key 7 is: Restricted Use (Approval Required)
- Value 7 is: 2018-09-28
- Key 8 is: Who Needs Access to the Room (Required for Restricted Access Only)
- Value 8 is: 1
- $Samanage_Array count is: 9
- $Final_Results Variable:
- name type value
- ---- ---- -----
- Type of Request drop_down_menu Add
- Room Name free_text Test Conference Room
- New Seating Capacity free_text 10
- Equipment in the Conference Room multi_select {Apple TV, TV}
- Building drop_down_menu Main Building
- Location Description free_text A Room in a Building
- Requested Date of Change date 2018-09-28
- Restricted Use (Approval Required) check_box 1
- Who Needs Access to the Room (Required for Restricted Access Only) free_text My Name
- Desired Output:
- Key 0 is: Type of Request
- Value 0 is: Add
- Key 1 is: Room Name
- Value 1 is: Test Conference Room
- Key 2 is: New Seating Capacity
- Value 2 is: 10
- Key 3 is: Equipment in the Conference Room
- Value 3 is: Apple TV, TV
- Key 4 is: Building
- Value 4 is: Main Building
- Key 5 is: Location Description
- Value 5 is: A Room in a Building
- Key 6 is: Requested Date of Change
- Value 6 is: 2018-09-28
- Key 7 is: Restricted Use (Approval Required)
- Value 7 is: 1
- Key 8 is: Who Needs Access to the Room (Required for Restricted Access Only)
- Value 8 is: My Name
Advertisement
Add Comment
Please, Sign In to add comment