Hi,
I know this is not a PowerShell forum, but perhaps it will eventually help someone else!
I need to execute the following command, all one one line:
curl -vvvv -XPUT --negotiate -u : --insecure -XPUT -g -H '"Content-Type: application/json"' -d "{\"hosttype\":\"server\", \"address\": [\"127.
0.0.1\"], \"parents\": [], \"tag\": [\"demo\"], \"umiworker\": \"gent\", \"notes\": \"this is a test\", \"url\": \"http://www.tomtom.com\"}" https://someservert/v1/host/test
However, no matter how many times I set a variable to this, it still fails.
Can anyone help me wrap this thing up and execute it in PS?
Thanks!
Hi,
I had found that triple quoting worked, but not for the brackets. Therefore, I used the Convertto-JSON with double quotes to give me the correct ouput. I did this only once because I will be using the string over and over again using variables in place of some required parameters. NOTE: the resultant command will run one line, which is necessary.
$json = '""Content-Type: application/json"" -d ""{""hosttype"":""server"",""address"": [""127.0.0.1""], ""parents"": [], ""tag"": ""demo""], ""umiworker"": ""gent"", ""notes"": ""this is a test"", ""url"": ""http://www.tomtom.com""} https://someservert/v1/host/test'| ConvertTo-JSON
$json contains this:
"\"\"Content-Type: application/json\"\" -d \"\"{\"\"hosttype\"\":\"\"server\"\",\"\"address\"\": [\"\"127.0.0.1\"\"], \"\"parents\"\": [], \"\"tag\"\": \"\"demo\"\"], \"
\"umiworker\"\": \"\"gent\"\", \"\"notes\"\": \"\"this is a test\"\", \"\"url\"\": \"\"http://www.tomtom.com\"\"} https://someservert/v1/host/test"
Then I set the entire command/parameters. I realize I could use the $json variable here, possibly, but for me there is no need.
$cmd = @"
curl.exe -XPUT - H "\"\"Content-Type: application/json\"\" -d \"\"{\"\"hosttype\"\":\"\"server\"\",\"\"address\"\": [\"\"127.0.0.1\"\"], \"\"parents\"\": [], \"\"tag\"\": \"\"demo\"\"], \"
\"umiworker\"\": \"\"gent\"\", \"\"notes\"\": \"\"this is a test\"\", \"\"url\"\": \"\"http://www.tomtom.com\"\"} https://someservert/v1/host/test"
"@
Hope this helps someone else!
Did you already try something like this ?
Just double the quote where a quote is needed inside the string
Those are 2 lines.
$cmd = "curl -vvvv -XPUT --negotiate -u : --insecure -XPUT -g -H ""Content-Type: application/json"" -d ""{""hosttype"":""server"",""address"": [""127.0.0.1""], ""parents"": [], ""tag"": ""demo""], ""umiworker"": ""gent"", ""notes"": ""this is a test"", ""url"": ""http://www.tomtom.com""} https://someservert/v1/host/test"
Invoke-Command -ScriptBlock {&$cmd}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I had found that triple quoting worked, but not for the brackets. Therefore, I used the Convertto-JSON with double quotes to give me the correct ouput. I did this only once because I will be using the string over and over again using variables in place of some required parameters. NOTE: the resultant command will run one line, which is necessary.
$json = '""Content-Type: application/json"" -d ""{""hosttype"":""server"",""address"": [""127.0.0.1""], ""parents"": [], ""tag"": ""demo""], ""umiworker"": ""gent"", ""notes"": ""this is a test"", ""url"": ""http://www.tomtom.com""} https://someservert/v1/host/test'| ConvertTo-JSON
$json contains this:
"\"\"Content-Type: application/json\"\" -d \"\"{\"\"hosttype\"\":\"\"server\"\",\"\"address\"\": [\"\"127.0.0.1\"\"], \"\"parents\"\": [], \"\"tag\"\": \"\"demo\"\"], \"
\"umiworker\"\": \"\"gent\"\", \"\"notes\"\": \"\"this is a test\"\", \"\"url\"\": \"\"http://www.tomtom.com\"\"} https://someservert/v1/host/test"
Then I set the entire command/parameters. I realize I could use the $json variable here, possibly, but for me there is no need.
$cmd = @"
curl.exe -XPUT - H "\"\"Content-Type: application/json\"\" -d \"\"{\"\"hosttype\"\":\"\"server\"\",\"\"address\"\": [\"\"127.0.0.1\"\"], \"\"parents\"\": [], \"\"tag\"\": \"\"demo\"\"], \"
\"umiworker\"\": \"\"gent\"\", \"\"notes\"\": \"\"this is a test\"\", \"\"url\"\": \"\"http://www.tomtom.com\"\"} https://someservert/v1/host/test"
"@
Hope this helps someone else!