I'm having a problem passing an array to an Azure deployment template. If only one object existed, PowerShell "converted" it to a string. In the example below, $a returned from a function that receives a VM according to the tag value. I pass $a to the New-AzureRmResourceGroupDeployment , wrapping it in @() . For example:
$TemplateParameterObject=@{ VMObject=@($a) } New-AzureRmResourceGroupDeployment -ResourceGroupName $RG -Name "TestVmByRole" -Mode Incremental -DeploymentDebugLogLevel All -TemplateFile $templatePath -TemplateParameterObject $TemplateParameterObject -verbose
VMObject is one of the template options.
This may not be the most technical / reliable way to do this, but that's enough for Azure.
Update
Good thing worked above. I tried all of the above and some, but the only way I was able to pass $vmObject as an array compatible with the deployment template, with one element as follows (I expect MS to play again (this was a report and a bug fix in 2015)) :
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") foreach($vmObject in $vmObjects) { #$vmTemplateObject = $vmObject $asJson = (ConvertTo-Json -InputObject $vmObject -Depth 10 -Verbose) #-replace '\s','' $DeserializedJson = (New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer -Property @{MaxJsonLength=67108864}).DeserializeObject($asJson) }
$vmObjects is the output of Get-AzureRmVM.
I pass $DeserializedJson to the deployment pattern parameter (type array).
For reference, the perfect New-AzureRmResourceGroupDeployment throws
"The template output '{output_name}' is not valid: The language expression property 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Expression.Expressions.JTokenExpression' can't be evaluated.."
woter324 Nov 29 '17 at 20:38 on 2017-11-29 20:38
source share