Open ghost opened 5 years ago
Hi Marc,
When I check the Properties parameter for the New-AzResource cmdlet via Get-Help New-AzResource -parameter Properties I read that it needs to be a System.Management.Automation.PSObject.
Can you verify the type of object for the $JsonDataUnescape variable? Is this of type System.Management.Automation.PSObject?
@Marc-013 Hey Marc, in addition to the question proposed above, is there any reason that you're not using the New-AzResourceGroupDeployment
command to create this resource?
Well System.Management.Automation.PSObject is just the base object class for Powershell. I have the same problem and I verified that the -properties argument was a PSObject with a .Length property. Notice the object type mentioned in the error message is 'ResourceProxyDefinition'. I don't have any ideas what that is about.
and this page is about all Google can find when searching for: ResourceProxyDefinition (no spaces). And there are no hits when searching the code of this repo. So, Obiwan, you are my only hope!
Now, I think the issue for @Mark-013 was that he was feeding a JSON string to new-azresource. It has to be an object. Note these lines:
$JsonData = Get-Content $ImageTemplateFilePath | ConvertFrom-Json $ConvertedJsonData = $JsonData | ConvertTo-Json -Depth 10 -Compress $JsonDataUnescape = $ConvertedJsonData | ForEach-Object -Process { [System.Text.RegularExpressions.Regex]::Unescape($_) }
So, your template file is JSON, you parse that into a PS Object with ConvertFrom-Json. Then you convert it back to the JSON string to do the unescape. Then you pass that string as the -properties argument. Instead you need to pass the output from ConvertFrom-Json.
I was making the same mistake in a different way. Once I took care of that, things moved on to a new error:
new-azresource : InvalidRequestContent : The request content was invalid and could not be deserialized: 'Could not find member 'dependsOn' on object of type 'ResourceProxyDefinition'. Path 'dependsOn'.'.
Now, there is a dependsOn field in the Json (for both of us) with a value of an empty array. That is properly converted to an empty array after ConvertFrom-Json. So, what it is complaining about is present.
@Marc-013 , could you share what reference your template is created based on?
Description
New-AzResource throws error when attempting to upload an Azure Image Builder Image Template.
Steps to reproduce
Create json template 'imageTemplateRhel76.json'
Execute PowerShell code
Environment data
Module versions
Debug output
PowerShell_transcript.computername.z4MPSrDJ.20190902090705.txt
Error output