VMware Cloud Community
Pilu1978
Enthusiast
Enthusiast

how to create json file using powercli

Hi,

I would like to create a json file from the below content replacing the <SERIAL> , <MD5_CHECKSUM>, <LINEAGE> etc with some values. 

{
   "data": {
     "type": "state-versions",
     "attributes": {
       "serial": <SERIAL>,
       "md5": "<MD5_CHECKSUM>",
       "lineage": "<LINEAGE>",
       "state": "<BASE64_CONTENT>"
     }
   } 

I have tried to achieve this with below code:

$obj = @{
"data" = @{
"types" = "state-versions"
"attributes" = @{
"serial" = $integer
"md5" = $md5.hash
"lineage" = $lineage
"state" = $Encoded
}
}
}
# Convert object to JSON
$json = $obj | ConvertTo-Json
# Save JSON to file
$json | Set-Content -Path $jsonFile

However whenever I am pushing this json file to Vxrail Manager using invoke-restmethod  to update some properties, I am getting some conflict error which depicts that there is some issue with my json file formatting.

What is the best way of creating this json file using powercli.

0 Kudos
1 Reply
LucD
Leadership
Leadership

The PowerShell ConvertTo-Json cmdlet creates a valid JSON file.
What exactly is the error you are getting?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos