Azure 自定义脚本扩展找不到脚本文件



我正在使用Powershell和JSON文件来创建新的VM。JSON 文件的最后一部分指示新创建的 VM 运行文件。我可以验证(通过 Azure 门户和 Powershell(该文件是否存在于 JSON 文件中给定的 URL 中。

然而,VM以结果ProvisioningState:Failed结束,因为VM has reported a failure when processing extension 'CustomScriptExtension'. Error message: "Finished executing command"令人沮丧的矛盾。(我们在使用domainjoin CustomScriptExtension时也遇到了问题,它也"失败"并显示"成功"消息。

该脚本是一个简单的CMD文件,应该C:UsersPublicDocumentsrunonce.log创建文件,但这不会发生,所以我想该文件不会运行。

但是,VM 已创建,然后我可以手动登录并正常运行文件。因此,这不应该是用户权限之类的问题。

编辑:此评论指出"CustomScriptExtension不以本地管理员权限运行",但我认为这不是这里的问题。

我错过了什么?

以下是 JSON 的相关部分:

...
"resources": [
    ...
    {
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(parameters('vmName'),'/CustomScriptExtension')]",
    "apiVersion": "2015-05-01-preview",
    "location": "[resourceGroup().location]",
    "dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"],
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.2",
        "settings": {
            "fileUris": ["[concat(parameters('scriptFilePath'),parameters('scriptFileName'))]"],
            "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file ',parameters('scriptFileName'))]"
        }
    }
}]

并且我已经验证了scriptFilePathscriptFileNamehttps://euwest2766.blob.core.windows.net/script/的,并且run-once.cmd对应于 Azure 中显示的 blob URL。我甚至尝试将该 Azure Blob URL 放入 JSON 中,结果相同。

这不起作用,因为你正在尝试通过Powershell运行批处理文件。

您需要更改此设置 -

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file ',parameters('scriptFileName'))]"

对此

    "commandToExecute": "[concat('cmd /s',parameters('scriptFileName'))]"

这应该按预期执行。

最新更新