I’m trying to create a new Azure ARM deployment file scripted based on an existing ARM template.
Basically what I do is:
The problem I’m having now, is that the original JSON file has the storageprofile.imagereference enabled which needs to be deleted from the new JSON file.
I’ve tried to set the value of it (storageprofile.imagereference.id = $null) but ARM doesn’t like that and wants the whole storageprofile.imagereference entry removed.
So in my Pshell, my VMObjectFile is read like:
$VMObjectFile = (Get-Content $ImportFile | Out-String | ConvertFrom-Json)
And the property I want to remove is set on:
$VMObjectFile.resources.properties.storageProfile.imageProfile
But how do I delete the whole tree? I already got rid of the “id” value and afterward can set the $VMObjectFile.resources.properties.storageProfile.imageProfile to $null (removing the id attribute),
But how do I completely remove imagereference from the subtree $VMObjectFile.resources.properties.storageProfile as there are multiple entries that still exists under that path:
$VMObjectFile.resources.properties.storageProfile.osDisk
$VMObjectFile.resources.properties.storageProfile.dataDisk
Removing properties from a PowerShell object is not as obvious as one would think:
$data = '{"a":{"b":{"c":"something","d":"another thing"}}}' | ConvertFrom-Json
$data.a.b.PSObject.Properties.Remove("c")
$data | ConvertTo-Json -Compress
Result:
{"a":{"b":{"d":"another thing"}}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With