Azure CLI run-command invoke RunPowerShellScript with parameters

有些话、适合烂在心里 提交于 2020-07-07 11:00:05

问题


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?


回答1:


in this case using the second suggested notation worked:

--parameters first=xxx second=yyy

although according to the docs both ways should be fine



来源:https://stackoverflow.com/questions/56578122/azure-cli-run-command-invoke-runpowershellscript-with-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!