Reputation: 788
I've been trying to run a script on an Azure VM that requires parameters passed to it like so;
az vm run-command invoke -g <resource group> -n <vm name> --command-id RunPowerShellScript --scripts "@....\Desktop\write-host.ps1" --parameters First Second
I have done this succesfully using the AzureRM modules in the following way;
Invoke-AzureRmVMRunCommand -ResourceGroupName <resource group> -VMName <vm name> -CommandId "RunPowerShellScript" -ScriptPath "....\Desktop\write-host.ps1" -Parameter @{ "first" = "First"; "second" = "Second; }
The write-host.ps1 script is very simple and is as follows;
param(
[string]
$first,
[string]
$second
)
Write-Host "$first and $second"
I cannot get the Azure CLI command to find the parameters. I've tried reading the documentation here, I've tried passing it in in a whole manner of different ways, some of which involve;
--parameters [first=]First [second=]Second
--parameters "[first=]First [second=]Second"
--parameters "`"First`" `"Second`""
--parameters @{"First" = "first"; "second" = "Second"}
The only time I can get it to semi work is when I pass in the variables like follows;
--parameters "`First`" `"Second`" `"Third`""
--parameters "First Second Third"
In which case it only prints out "Second and Third", it seems to ignore "First"
I want to execute these in a PowerShell script using AzureCLI commands but I've failed to execute it both in a Command window and in PowerShell.
Is any one able to tell me how to successfully pass in parameters, named or otherwise, into a PowerShell script using the AzureCLI run-command command?
Upvotes: 2
Views: 2363
Reputation: 72176
in this case using the second suggested notation worked:
--parameters first=xxx second=yyy
although according to the docs both ways should be fine
Upvotes: 4