I have created a VM in Azure, and I can run the following command from my local Windows 10 Powershell window:
az vm run-command invoke --command-id RunPowerShellScript --resource-group $ResourceGroup --name $AD1Name --scripts "@provision.ps1"
But when I put this line in a Powershell script file, CreateVMAndProvision.ps1, and run my CreateVMAndProvision.ps1 that also run the az vm create...
I get the following error:
"value": [
{
"code": "ComponentStatus/StdOut/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"message": "",
"time": null
},
{
"code": "ComponentStatus/StdErr/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"message": "At C:\\Packages\\Plugins\\Microsoft.CPlat.Core.RunCommandWindows\\1.1.5\\Downloads\\script6.ps1:1 char:1
+ @provision.ps1
+ ~~~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@provision'
can be used only as an argument to a command. To reference variables in an expression use
'$provision'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermitted
",
"time": null
}
]
}
The syntax of specifying my local provision.ps1 file to the az cli command as "@provision.ps1"
seem to be the problem, but I can not figure out how to solve this. I have tried to use double quotes, combination of double and single quotes, here string (@"..."@) and (@'...'@) without any success.
Anyone have an idea on how to solve this?
Thanks! :: Petter