Powershell query CMDB

Powershell query CMDB

Hi

I'm trying from Powershell query the cmdb with the provided API. Its not going so well :(

The code I have is the following and is resulting in permission denied html 401 error
$bodycmdb = @{OPERATION_NAME="READ";TECHNICIAN_KEY="$testkey";}
$resultcmdb = Invoke-RestMethod -Uri "$server/api/cmdb/ci/list/server/" -Method Post -body $bodycmdb


The below code that uses the api to query a request works like it should and returns an xml with the info of the request.

$bodyrequest = @{OPERATION_NAME="GET_REQUEST";TECHNICIAN_KEY="$testkey";}
$ticketid = ‘13971’
$resultrequest = Invoke-RestMethod -Uri $server/sdpapi/request/$ticketid/ -Method Post -Body $bodyrequest


I have also tried to get the results from the CMDB in the rest client Postman and there it works. So I am a little confused to way its not working when I call the the cmdb through Powershell.

Both Postman and the Invoke-RestMethod uses x-www-form-urlencoded for the Post method.

Best regards Peter Samuelsson Sodra Skogsagarna

                  New to ADSelfService Plus?