【发布时间】:2017-02-13 12:25:37
【问题描述】:
我正在尝试在使用 Azure RM 创建的 VM 上运行 powershell 脚本。我已经编写了一个使用 Rest api 创建 VM 的 C# 程序,现在我需要在 VM 上运行一个脚本,以便正确配置它。 I found this link that shows what to send 我遇到的问题是当我尝试创建扩展时,它总是以失败的配置状态结束,并且脚本没有运行。
我认为问题在于管理程序无法下载脚本,但是我无法从管理程序收到错误消息,而且我不知道我传递给的 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 的 URL
https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualMachines/{serverName}/extensions/{extensionName}?api-version=2017-03-30
【问题讨论】:
标签: c# rest azure-resource-manager