I bet @christopherlecky knows!
There are a couple of things.
- The XML for the command goes into the body.
- When passing the headers you are actually passing a hash map of values so you don’t use $ you use @
so it should look something like this :
$commserve = mycs.mydomain.com
$uri = $commserve + "/QCommand/qoperation%20execute"
$body = "<App_SetControlPanelParametersRequest>
<preventAdminAccessToUserData>true</preventAdminAccessToUserData>
</App_SetControlPanelParametersRequest>"
$headers = @{
$accept = "application/xml"
$authtoken = QSDK 38568012f4d1e8ee1841d283a47aa3ba78e124ea58354b5fc60f4dab8a63347d05cf5552484dafda3bfa4c5db84e580b1cb37bcf8e65b39f7f8549a443e6f78a2c7be3f31b3d845e24776c835e498e8e883bb40c46bd15af4f40ca94e823acedcdd4e9659e74b34a07a85c4586cd2ed914b6dce015874783ef768fda78183a4208930954a377f66eb56c8b92cexampl4s437a19317ca6ce7f3233d5a01aca35dbad93468b833f2cf71010809006a937670adce711ca8be46638e8
$Content-type = "application/xml"
}
$qoperationresult = Invoke-restmethod -uri $uri -body $body -headers @headers
Based on the following link:
The uri should follow the format <webservice>/QCommand/qoperation execute
Please double check the second line to make sure it matches your web services.
I don’t have time to test it, but its not far from this.
OK, your corrections are clearly “things I wouldn’t have thought of in a million years,” so thank you for that. I’ll try to be amused (and impressed) that my $headers/@headers confusion was tolerated by Powershell in my prior work
Off to experiment, with gratitude. .
Hmm you may be right on that second one.
I was free styling it so I just kind of went with my first thought on it.
You actually should be able to pass the hash map as a parameter.
I was confusing it with splatting all the parameters which would look something like so:
Starting with something like this:
$commserve = mycs.mydomain.com
$uri = $commserve + "/QCommand/qoperation%20execute"
$parameters = ${
$body = "<App_SetControlPanelParametersRequest>
<preventAdminAccessToUserData>true</preventAdminAccessToUserData>
</App_SetControlPanelParametersRequest>"
$headers = @{
$accept = "application/xml"
$authtoken = QSDK 38568012f4d1e8ee1841d283a47aa3ba78e124ea58354b5fc60f4dab8a63347d05cf5552484dafda3bfa4c5db84e580b1cb37bcf8e65b39f7f8549a443e6f78a2c7be3f31b3d845e24776c835e498e8e883bb40c46bd15af4f40ca94e823acedcdd4e9659e74b34a07a85c4586cd2ed914b6dce015874783ef768fda78183a4208930954a377f66eb56c8b92cexampl4s437a19317ca6ce7f3233d5a01aca35dbad93468b833f2cf71010809006a937670adce711ca8be46638e8
$Content-type = "application/xml"
}
}
$qoperationresult = Invoke-restmethod @parameters
Rewriting it to something like this :
$commserve = mycs.mydomain.com
$parameters = ${
uri = ""
body = ""
headers = @{
accept = ""
authtoken = ""
content-type= ""
}
}
$parameters.uri = $commserve + "/QCommand/qoperation%20execute"
$parameters.body = "<App_SetControlPanelParametersRequest<preventAdminAccessToUserData>true</preventAdminAccessToUserData></App_SetControlPanelParametersRequest>"
$parameters.headers.accept = "application/xml"
$parameters.headers.authtoken = "QSDK 38568012f4d1e8ee1841d283a47aa3ba78e124ea58354b5fc60f4dab8a63347d05cf5552484dafda3bfa4c5db84e580b1cb37bcf8e65b39f7f8549a443e6f78a2c7be3f31b3d845e24776c835e498e8e883bb40c46bd15af4f40ca94e823acedcdd4e9659e74b34a07a85c4586cd2ed914b6dce015874783ef768fda78183a4208930954a377f66eb56c8b92cexampl4s437a19317ca6ce7f3233d5a01aca35dbad93468b833f2cf71010809006a937670adce711ca8be46638e8"
$parameters.headers.content-type = "application/xml"
$qoperationresult = Invoke-restmethod @parameters
You could then set the object properties through dot notation.
The @headers notation simply didn’t work. Moving the XML to -body was what I needed, though, so full credit for that.