Forum Discussion

DanSchuster_234's avatar
DanSchuster_234
Historic F5 Account
Jan 19, 2016

Powershell calling a script

Hi,

 

How do you call a script via PowerShell? Looking to do the equivalent of this successful curl command but via PS:

 

curl -k -u admin -H "Content-Type: application/json" -X POST https://10.1.1.245/mgmt/tm/cli/script -d "{\"command\":\"run\",\"utilCmdArgs\":\"dtstest 10.1.10.1\"}"

 

Attempted to do the PowerShell call similar to the curl call but it errors out:

 

$body = @{ utilCmdArgs = "dtstest 10.1.10.1" command = "run" }

 

Invoke-RestMethod -Credential admin -Method POST -ContentType "application/json" -Body $body -Uri "https://10.1.1.245/mgmt/tm/cli/script"

 

ERROR:

 

Invoke-RestMethod : {"code":400,"message":"Found invalid JSON body in the request.","errorStack":[]}

 

Thanks, -Dan

 

  • Your body needs to be just like it is in your curl example. It needs to be in JSON format. i.e.

    $body = '{
                "command":"run",
                "utilCmdArgs":"dtstest 10.1.10.1"
             }'
    
  • Your body needs to be just like it is in your curl example. It needs to be in JSON format. i.e.

    $body = '{
                "command":"run",
                "utilCmdArgs":"dtstest 10.1.10.1"
             }'
    
  • Your body needs to be just like it is in your curl example. It needs to be in JSON format. i.e.

    $body = '{
                "command":"run",
                "utilCmdArgs":"dtstest 10.1.10.1"
             }'