The following is a test script i am running trying to have the name change on the JSON file. Below is my PowerShell script. I would like my "$test" variable to pass through to the JSON file but it is staying
Powershell Script PS 5.1
$test = "vmNAMEtest"
New-AzResourceGroupDeployment `
-ResourceGroupName 'test' `
-Name '$test' `
-TemplateUri '.Documentsazuredeploy.json'
JSON
"vmName": {
"type": "string",
"defaultValue": "simple-vm",
"metadata": {
"description": "Name of the virtual machine."
}
},
Everytime the script is automatically the defaultValue "simple-vm" but i’d like to pass the $test value
Some things I’ve tried: in the JSON code:
"defaultValue": "$test"
– this did not work
"defaultValue": "'+$test+'"
– also no luck
2
Answers
thanks again to Rithwik, Mclayton, and Mklement really made everything come together, wish I could give it a thumbs up but stackoverflow is silly and wont let me because I am a noob acc. Any who here's the solution:
Nothing had to be done on the JSON template side just keeping it how it is and having the place holder as a backup. Only thing I had to change was on the powershell script side. Adding TemplateParameterObject line and following what Mclayton said for the answer or visually what Rithwik said agreeing to Mclayton. One issue I was coming across when doing this was I forgot to add "`" at the end of the TemplateUri line - not allowing the code to reach the TemplateParameterObject line
This script is extremely helpful when populating Azure subscriptions with Azure resources through powershell
Sorry imma noob, but thanks to everyone mentioned for all your help and kindness
I have reproduced in my environment, I do agree with @mclayton and below are my expected results:
Output: