我正在尝试在使用Azure RM创建的VM上运行powershell脚本。我编写了一个使用Rest api创建VM的C#程序,现在我需要在VM上运行一个脚本,以便正确配置。 I found this link that shows what to send 我遇到的问题是当我尝试创建扩展时,它总是以Provisioning State of Failed结束,并且脚本没有运行。
我认为问题是管理程序无法下载脚本,但是我无法从管理程序获取错误消息,而且我不知道我传递给JSON的JSON有什么问题。管理程序。
这是我发送的用于创建自定义脚本扩展的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}\" " +
" } " +
" } " +
"} " +
"";
这是我正在做的PUT
的网址https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualMachines/{serverName}/extensions/{extensionName}?api-version=2017-03-30
答案 0 :(得分:0)
我正在使用类似的技术在Service Fabric虚拟机规模集上安装.net 4.6和其他设备(但是来自json模板)。
...
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7",
"autoUpgradeMinorVersion": false,
"settings": {
"fileUris": [
"https://gist.githubusercontent.com/DenisPitcher/d06c6cbc64765c1eb7e8c731964f2a5e/raw/6c2b87aa3e825950ad61b368490b8862f9345856/InstallNetFx46.ps1"
],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File InstallNetFx46.ps1"
},
"forceUpdateTag": "RerunExtension"
},
"name": "CustomScriptExtensionInstallNet46"
...
那么,有什么区别:
但无论如何,应该能够在https://resources.azure.com/看到错误。