[英]Azure customscriptextension can't find script file
我正在使用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"
VM has reported a failure when processing extension 'CustomScriptExtension'. Error message: "Finished executing command"
這令人沮喪地矛盾。 (我們也遇到了domainjoin
CustomScriptExtension的問題,它也因“成功”消息而“失敗”。)
該腳本是一個簡單的CMD文件,應該創建文件C:\\Users\\Public\\Documents\\runonce.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'))]"
}
}
}]
我已經驗證了scriptFilePath
和scriptFileName
是https://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'))]"
這應該按預期執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.