Visual studio code 无法执行";自定义脚本扩展名“;在Azure VM上使用linux子系统中的Azure CLI

Visual studio code 无法执行";自定义脚本扩展名“;在Azure VM上使用linux子系统中的Azure CLI,visual-studio-code,azure-cli,pester,azure-vm-templates,Visual Studio Code,Azure Cli,Pester,Azure Vm Templates,我正在为我的项目开发部署后Pester验证脚本。我需要使用Azure CLI将pester脚本作为自定义脚本扩展推送到VM中 以下是我执行的命令: az vm extension set --resource-group SomeRG--vm-name SimpleVM --name customScript --publisher Microsoft.Azure.Extensions --settings '{"fileUris": ["https://github.com/myname/

我正在为我的项目开发部署后Pester验证脚本。我需要使用Azure CLI将pester脚本作为自定义脚本扩展推送到VM中

以下是我执行的命令:

az vm extension set --resource-group SomeRG--vm-name SimpleVM --name 
customScript --publisher Microsoft.Azure.Extensions --settings '{"fileUris": 
["https://github.com/myname/DSCConfig/blob/master/pester.ps1"], 
"commandToExecute":"powershell -ExecutionPolicy Unrestricted -File 
pester.ps1"}'  --version 2.0
在执行上述命令后,我在Linux界面中得到以下错误:

部署失败。相关ID: 8ba16fc0-fea6-4650-bb0a-2b73c9613dfe。处理者 “Microsoft.Azure.Extensions.customScript”已报告VM失败 扩展名“customScript”,终端错误代码为“1007”,错误为 消息:“插件安装失败(名称: Microsoft.Azure.Extensions.customScript,版本2.0.6),例外 指定的可执行文件不是此操作系统的有效应用程序 站台。”

在检查VM上的扩展时,发现插件(名称:Microsoft.Azure.Extensions.customScript,版本2.0.6)的状态为“正在转换”,详细信息为安装失败,但指定的可执行文件对此操作系统平台无效)

或者,我尝试与其他出版商合作:Microsoft.Compute和Microsoft.OSTCExtensions


不幸的是,它们都没有起作用。在过去的两天里,我一直被困在这一步。非常感谢您的帮助

我认为您可能使用了错误的自定义脚本扩展(我认为您使用的是Linux虚拟机)。我认为您应该使用名为“CustomScriptExtension”的版本,发布者为“Microsoft.Compute”,版本设置为“1.9”,如文档所示

具体而言,请尝试以下命令:

az vm extension set --resource-group SomeRG--vm-name SimpleVM --name CustomScriptExtension --publisher Microsoft.Compute --settings '{"fileUris": ["https://github.com/myname/DSCConfig/blob/master/pester.ps1"], "commandToExecute":"powershell -ExecutionPolicy Unrestricted -File pester.ps1"}' --version 1.9

该错误似乎表明您的目标VM不是Windows计算机,而是不支持Windows PowerShell的其他操作系统。如果是这种情况,现在就有跨平台的PowerShell Core,但我个人不知道您是否可以通过自定义脚本扩展使用它。谢谢您的输入标记。但我尝试访问的虚拟机是在windows操作系统上配置的简单虚拟机。我使用了Microsoft.Azure.Extensions,它抛出错误“'插件(名称:Microsoft.Azure.Extensions.customScript,版本2.0.6)的安装失败,但指定的可执行文件不是此操作系统平台的有效应用程序。”“太棒了,我现在得到了错误的修复。正如您正确地提到的,我尝试使用publisher作为micosoft.compute,名称为CustomScriptExtension,它的工作非常出色。谢谢你。