Azure CLI运行命令使用参数调用RunPowerShellScript [英] Azure CLI run-command invoke RunPowerShellScript with parameters

查看:51
本文介绍了Azure CLI运行命令使用参数调用RunPowerShellScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在Azure VM上运行脚本,该脚本需要像这样传递参数;

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

我已通过以下方式成功使用AzureRM模块完成了此操作:

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; }

write-host.ps1脚本非常简单,如下所示;

The write-host.ps1 script is very simple and is as follows;

param(
    [string]
    $first,

    [string]
    $second
)

Write-Host "$first and $second"

我无法获取Azure CLI命令来查找参数.我已经尝试阅读文档

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"

我想使用AzureCLI命令在PowerShell脚本中执行这些操作,但是在Command窗口和PowerShell中都无法执行.

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.

有谁能告诉我如何使用AzureCLI run-command命令将参数(已命名或以其他方式成功地)传递到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?

推荐答案

在这种情况下,使用第二个建议的符号有效:

in this case using the second suggested notation worked:

--parameters first=xxx second=yyy

尽管根据文档,两种方法都可以

although according to the docs both ways should be fine

这篇关于Azure CLI运行命令使用参数调用RunPowerShellScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆