azure - 从 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 调用命令的文档没有提及设置操作系统类型。
解决方案
我认为使用续行(在行的最后)对您的问题`
是偶然的。
除了使用变量与文字之外,您的多行命令和您的工作单行命令之间的关键区别是:
--command-id RunPowerShellScript
与--command-id RunShellScript
.
看起来您的目标虚拟机是Linux机器,并且--command-id RunPowerShellScript
那里不支持,而支持--command-id RunShellScript
。
az vm run-command list ...
显然可以用来发现支持的--command-id
值。
推荐阅读
- nlp - 乔姆斯基层次结构——真实语言的例子
- php - 获取附加到 WooCommerce 中产品的所有“活动”属性分类法?
- typescript - 如何在 Typescript 中包装 Express 路线?
- c# - 如何在 C# 中获取包含 KeyValuePair 的列表值?
- postgresql - 如何更改postgres的默认用户名
- python - 从循环更新语句中组合字典
- python - 每次运行 python 脚本时更改目录
- node.js - 无效或意外令牌,我今天试图让我的机器人不和谐,但出现了这个错误
- spring - 将 Spring Boot 2.2.7 升级到 Spring Boot 2.3.0 时出错
- linux - 重命名拆分生成的文件