2

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?

Connor Dickson
  • 770
  • 3
  • 12
  • 1
    how about `--parameters first=xxx second=yyy`? but it should works as `--parameters first second` – 4c74356b41 Jun 13 '19 at 10:11
  • @4c74356b41 that worked! Passing it in as '--parameters first=First second=Second' worked but passing it in as '--parameters First Second' did not! I've sent a feedback request [here](https://github.com/Azure/azure-cli/issues/9658) to Microsoft about adding examples or clarifying their documentation. Thanks for your help! – Connor Dickson Jun 13 '19 at 10:31

1 Answers1

4

in this case using the second suggested notation worked:

--parameters first=xxx second=yyy

although according to the docs both ways should be fine

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • Thanks for your help, this was the solution! In the [documentation bug](https://github.com/Azure/azure-cli/issues/9658) I raised with them I did pass comment that passing them in without being named doesn't work – Connor Dickson Jun 13 '19 at 10:36