首页 > 解决方案 > 从 PowerShell 运行 Azure CLI 命令的操作系统类型冲突

问题描述

我在 Windows 10 Professional PowerShell 脚本中运行 Azure CLI 命令,并收到以下错误:

(Conflict) Run command OS type 'Windows' does not match the target OS Linux.

PowerShell 版本:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1237

失败的 PowerShell 脚本:

$ResourceGroup= "Development"
$VmName = "ubuntu-test"

 az vm run-command invoke `
--resource-group $ResourceGroup `
--name $VmName `
--command-id RunPowerShellScript `
--scripts "ufw disable"

注意:` 字符是反引号。与波浪号在同一键上的那个~

没有行继续反引号的相同命令有效:

az vm run-command invoke --resource-group Development --name ubuntu-test --command-id RunShellScript --scripts "ufw disable"

如果我执行 Write-Host,则输出是带有正确参数的单行减去 --script 命令周围的引号。

Write-Host az vm run-command invoke `
--resource-group $ResourceGroup `
--name $VmName `
--command-id RunPowerShellScript `
--scripts "ufw disable"

az vm run-command invoke --resource-group Development --name ubuntu-test --command-id RunPowerShellScript --scripts ufw disable

AZ CLI 调用命令的文档没有提及设置操作系统类型。

az VM 运行命令调用

标签: azurepowershellazure-cliazure-vm

解决方案


我认为使用续行(在行的最后)对您的问题`偶然的。

除了使用变量与文字之外,您的多行命令和您的工作单行命令之间的关键区别是:
--command-id RunPowerShellScript--command-id RunShellScript
.

看起来您的目标虚拟机是Linux机器,并且--command-id RunPowerShellScript那里不支持,而支持--command-id RunShellScript

az vm run-command list ...显然可以用来发现支持的--command-id值。


推荐阅读