gregj529

Help me

Sep 27th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. $ApiRoot = "https://api.samanage.com"
  2. $ApiIncidents = "https://api.samanage.com/incidents"
  3. $ApiGroup = "https://api.samanage.com/groups"
  4. $Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
  5. $Headers.Add("Accept", 'application/vnd.samanage.v2.1+json')
  6. $Headers.Add("X-Samanage-Authorization", 'Bearer BunchOfSecretStuff')
  7. $ContentType = "application/json"
  8. $Incident = Read-Host "Enter Incident ID"
  9. $Incident = $Incident + ".json"
  10. $URI = "$ApiIncidents/$Incident" + "?layout=long"
  11. $SAM_Results = $(Invoke-WebRequest -Header $Headers -ContentType $ContentType -Method Get -UseBasicParsing -URI $URI).Content | ConvertFrom-Json
  12. $Final_Results = $SAM_Results.request_variables | Select Name,Type,Value
  13. $Count = $Final_Results.Count
  14. $Type_Var = "Type of Request"
  15. $Room_Var = "Room Name"
  16. $Seating_Var = "New Seating Capacity"
  17. $Equipment_Var = "Equipment in the Conference Room"
  18. $Building_Var ="Building"
  19. $LocationDescription_Var = "Location Description"
  20. $RequestDate_Var = "Requested Date of Change"
  21. $Restricted_Var = "Restricted Use (Approval Required)"
  22. $Access_Var = "Who Needs Access to the Room (Required for Restricted Access Only)"
  23. $Samanage_Array = @($Type_Var,$Room_Var,$Seating_Var,$Equipment_Var,$Building_Var,$LocationDescription_Var,$RequestDate_Var,$Restricted_Var,$Access_Var)
  24. $Results_Array = @()
  25. $Equipment_Array = @()
  26. $Var_Count = $Samanage_Array.Length
  27.  
  28.  
  29.  
  30. for ($g = 0; $g -lt $Var_Count ; $g++) {
  31. for ($j = 0; $j -lt $Count ; $j++) {
  32. if ($Final_Results.name[$j] -eq $Samanage_Array[$g]) {
  33. Write-Host "Key $j is:" $Final_Results.name[$j]
  34. $Results_Array += $Final_Results.value[$j]
  35. Write-Host "Value $j is:" $Final_Results.value[$j]
  36. Write-Host ""
  37. }
  38. }
  39. }
  40.  
  41.  
  42. if ($Debug ='1') {
  43. Write-Host '$Samanage_Array count is:' $Samanage_Array.Length
  44. }
  45.  
  46. Write-Host ""
  47. pause
  48.  
  49.  
  50. Various Output: All values shifted down by one because Key 3 contains 2 Values, AppleTV and TV.
  51. Key 0 is: Type of Request
  52. Value 0 is: Add
  53.  
  54. Key 1 is: Room Name
  55. Value 1 is: Test Conference Room
  56.  
  57. Key 2 is: New Seating Capacity
  58. Value 2 is: 10
  59.  
  60. Key 3 is: Equipment in the Conference Room
  61. Value 3 is: Apple TV
  62.  
  63. Key 4 is: Building
  64. Value 4 is: TV
  65.  
  66. Key 5 is: Location Description
  67. Value 5 is: Main Building
  68.  
  69. Key 6 is: Requested Date of Change
  70. Value 6 is: A Room in a Building
  71.  
  72. Key 7 is: Restricted Use (Approval Required)
  73. Value 7 is: 2018-09-28
  74.  
  75. Key 8 is: Who Needs Access to the Room (Required for Restricted Access Only)
  76. Value 8 is: 1
  77.  
  78. $Samanage_Array count is: 9
  79.  
  80.  
  81. $Final_Results Variable:
  82. name type value
  83. ---- ---- -----
  84. Type of Request drop_down_menu Add
  85. Room Name free_text Test Conference Room
  86. New Seating Capacity free_text 10
  87. Equipment in the Conference Room multi_select {Apple TV, TV}
  88. Building drop_down_menu Main Building
  89. Location Description free_text A Room in a Building
  90. Requested Date of Change date 2018-09-28
  91. Restricted Use (Approval Required) check_box 1
  92. Who Needs Access to the Room (Required for Restricted Access Only) free_text My Name
  93.  
  94.  
  95. Desired Output:
  96. Key 0 is: Type of Request
  97. Value 0 is: Add
  98.  
  99. Key 1 is: Room Name
  100. Value 1 is: Test Conference Room
  101.  
  102. Key 2 is: New Seating Capacity
  103. Value 2 is: 10
  104.  
  105. Key 3 is: Equipment in the Conference Room
  106. Value 3 is: Apple TV, TV
  107.  
  108. Key 4 is: Building
  109. Value 4 is: Main Building
  110.  
  111. Key 5 is: Location Description
  112. Value 5 is: A Room in a Building
  113.  
  114. Key 6 is: Requested Date of Change
  115. Value 6 is: 2018-09-28
  116.  
  117. Key 7 is: Restricted Use (Approval Required)
  118. Value 7 is: 1
  119.  
  120. Key 8 is: Who Needs Access to the Room (Required for Restricted Access Only)
  121. Value 8 is: My Name
Advertisement
Add Comment
Please, Sign In to add comment