我开始在Azure中测试自定义扩展,并从非常简单的json和ps1脚本开始。我的json文件看起来像这样:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'),'/RunDateTimeScript')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://github.com/username/repo/blob/master/writedatetime.ps1"
],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File writedatetime.ps1"
}
}
}
]
}
我的powershell脚本是一个单行代码:
(Get-Date).DateTime | Out-File "C:\Testing.txt" -Append
但是,当我运行常规的powershell部署命令时:
New-AzureRmResourceGroupDeployment -ResourceGroupName MyResources -TemplateFile .\extensionexample.json -vmName MyVmName01
结果我失败了:
“消息”:“ VM处理扩展时报告了故障 'RunDateTimeScript'。错误消息:\“执行命令完成\”。“
那我做错了什么以及如何解决呢?
答案 0 :(得分:1)
与此有关的问题非常愚蠢。我为github使用了错误的网址,因为它应该是原始网址,而不是模板中的网址。即https://raw.githubusercontent.com/username/repo/master/script.ps1