Convert curl script to powershell
i want convert curl script powershell. please me out in this?
here curl script needs converted
curl -x post --header 'content-type: application/json' --header 'accept: application/json' -d '{ "computers": [ "server123" ], "content": [ { "name": "execute-blankaction", "parameters": { "parametername": "string" } } ], "uid": "abcd", "description": "string", "email": "string" }' 'https://xyz.com/api/v1/job/'
here powershell script used. need computers, name , uid in powershell script. believe have screwed in body section of script due not getting computer information.
$cred=get-credential
$data = @{
computers='server123'
name='execute-blankaction'
uid= 'abcd'
}
$body=$data|convertto-json
$body
invoke-restmethod -uri 'https://xyz.com/api/v1/job/' -method post -body $body -credential $cred -contenttype 'application/json'
but getting message as
status_text : error: no computers[] entered. must enter @ least oneerror_text : can not execute job
status_code : 200
status : failed
rc : 1
hi rohith,
you can figure out how build object going reverse way, if have valid json:
@" { "computers": [ "server123" ], "content": [ { "name": "execute-blankaction", "parameters": { "parametername": "string" } } ], "uid": "abcd", "description": "string", "email": "string" } "@ | convertfrom-json
now converting other way, based on object saw this:
$body = @{ computers = @("server123") content = @(@{ name = "execute-blankaction" parameters = @{ parametername = "string" } }) uid = "abcd" description = "string" email = "string" } | convertto-json -depth 3
cheers,
fred
there's no place 127.0.0.1
Windows Server > Windows PowerShell
Comments
Post a Comment