我一直在尝试在 Azure VM 上运行一个脚本,该脚本需要像这样传递参数;
az vm run-command invoke -g <resource group> -n <vm name> --command-id RunPowerShellScript --scripts "@....\Desktop\write-host.ps1" --parameters First Second
我已经通过以下方式使用 AzureRM 模块成功完成了此操作;
Invoke-AzureRmVMRunCommand -ResourceGroupName <resource group> -VMName <vm name> -CommandId "RunPowerShellScript" -ScriptPath "....\Desktop\write-host.ps1" -Parameter @{ "first" = "First"; "second" = "Second; }
write-host.ps1 脚本非常简单,如下所示;
param(
[string]
$first,
[string]
$second
)
Write-Host "$first and $second"
我无法使用 Azure CLI 命令来查找参数。我尝试阅读文档here https://learn.microsoft.com/en-us/cli/azure/vm/run-command?view=azure-cli-latest#az-vm-run-command-invoke,我尝试过以各种不同的方式传递它,其中一些涉及;
--parameters [first=]First [second=]Second
--parameters "[first=]First [second=]Second"
--parameters "`"First`" `"Second`""
--parameters @{"First" = "first"; "second" = "Second"}
我唯一能让它半工作的时候是当我传入如下变量时;
--parameters "`First`" `"Second`" `"Third`""
--parameters "First Second Third"
在这种情况下,它只打印出“第二和第三”,它似乎忽略了“第一”
我想使用 AzureCLI 命令在 PowerShell 脚本中执行这些命令,但我无法在命令窗口和 PowerShell 中执行它。
有人能告诉我如何使用 AzureCLI run-command 命令成功地将参数(命名或其他方式)传递到 PowerShell 脚本中吗?