0
我試圖在使用Azure RM創建的虛擬機上運行powershell腳本。我編寫了一個使用Rest api創建虛擬機的C#程序,現在我需要在虛擬機上運行腳本,以便正確配置它。 I found this link that shows what to send 我遇到的問題是當我嘗試創建擴展時,它始終以配置失敗的狀態結束,並且腳本未運行。在Azure RM服務器上運行腳本
我認爲問題在於管理程序無法下載腳本,但是我無法從管理程序獲取錯誤消息,而且我不知道我傳遞給的JSON有什麼問題管理程序。
下面是我送創建自定義腳本擴展
string body =
"{ " +
$" \"type\" : \"Microsoft.Compute/virtualMachines/extensions\", " +
$" \"name\" : \"{extensionName}\", " +
" \"location\" : \"eastus\", " +
" \"tags\": { " +
$" \"displayName\": \"{extensionName}\" " +
" }, " +
" \"properties\": { " +
" \"publisher\": \"Microsoft.Azure.Extensions\", " +
" \"type\": \"CustomScript\", " +
" \"typeHandlerVersion\": \"2.0\", " +
" \"autoUpgradeMinorVersion\": true, " +
" \"settings\": { " +
$" \"fileUris\": [ \"https://{storageAccountName}.file.core.windows.net/scripts/TestScript1.ps1\", ], " +
" }, " +
" \"protectedSettings\": { " +
" \"commandToExecute\": \"PowerShell.exe -ExecutionPolicy Unrestricted -File TestScript1.ps1\", " +
$" \"storageAccountName\": \"{storageAccountName}\", " +
$" \"storageAccountKey\": \"{storageAccountAccessKey}\" " +
" } " +
" } " +
"} " +
"";
的JSON下面是我在做一個PUT到
https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualMachines/{serverName}/extensions/{extensionName}?api-version=2017-03-30
我做了您所建議的更改,但是我仍然收到相同的錯誤 – Rossini
當您在https://resources.azure.com找到您的資源時會看到什麼錯誤? –
你也可以查看虛擬機上的日誌以及C:\ WindowsAzure \ Logs \ Plugins,如果你沒有發現任何東西,那麼C:\ Packages \ Plugins \ Microsoft.Compute.CustomScriptExtension \ 1.7 \狀態,但這將比腳本更多地關於擴展。 –