Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. type Resource =
  2. | VM of VMResource
  3. | Unit of UnitResource
  4.  
  5. type VMResource = {
  6. ComputerName: string
  7. Ip: string
  8. Attributes: string[]
  9. }
  10.  
  11. type UnitResource = {
  12. UnitName: string
  13. Ip: string
  14. Username: string
  15. Password: string
  16. Attributes: string[]
  17. }
  18.  
  19. Add-Type -Path "pathtomydll.dll"
  20.  
  21. $fullRequestUrl = "http://localhost:2121/Resources/Get"
  22. $body = "{`"Id`":`"Test`",`"RequestedResources`":[{`"ResourceType`":{`"Case`":`"VM`"},`"Attributes`":[`"A1`",`"A2`"]},{`"ResourceType`":{`"Case`":`"Unit`"},`"Attributes`":[]}]}"
  23.  
  24. $resp = Invoke-WebRequest $fullRequestUrl -Method Post -Body $body -ContentType "application/json"
  25. $obj = [ServerProtocolTypes+GetResourcesResponse]::FromJson($resp)
  26. $obj.GetType() # GetResourcesResponse
  27.  
  28. Add-Type -Path "pathtomydll.dll"
  29.  
  30. $fullRequestUrl = "http://localhost:2121/Resources/Get"
  31. $body = "{`"Id`":`"Test`",`"RequestedResources`":[{`"ResourceType`":{`"Case`":`"VM`"},`"Attributes`":[`"A1`",`"A2`"]},{`"ResourceType`":{`"Case`":`"Unit`"},`"Attributes`":[]}]}"
  32.  
  33. $job = Start-Job -ScriptBlock { param($url, $reqBody) Add-Type -Path "pathtomydll.dll"; $resp = Invoke-WebRequest $url -Method Post -Body $reqBody -ContentType "application/json"; return [ServerProtocolTypes+GetResourcesResponse]::FromJson($resp) } -ArgumentList ($fullRequestUrl, $body)
  34. Wait-Job $job
  35. $obj = Receive-Job $job
  36. $obj.GetType() # PSObject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement