I am trying to deploy a VM and run an extensions powershell script using ARM Templates. The script below is responsible to run the extentions for the VM. As can be seen in the part:
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/../../install.ps1 '
The powershell will execute the script file from that location. I want to save the .ps1 file in a git repository and pass the link to the file instead of the local folder. Something like "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Uri https://raw.githubusercontent.com/.../install.ps1
How can I achieve this?
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('virtualMachineName'), '/' ,parameters('virtualMachineName'), 'installGW')]",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"tags": {
"vmname": "[parameters('virtualMachineName')]"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[parameters('scriptURL')]"
]
},
"protectedSettings": {
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/.../.../install.ps1 ', if(equals(parameters('existingDataFactoryVersion'), 'V2'), listAuthKeys(parameters('irId'), '2017-09-01-preview').authKey1, listAuthKeys(parameters('irId'), '2015-10-01').key1))]"
}
}
}
]
The proper way to do it is to set URL https://raw.githubusercontent.com/.../install.ps1
(URL must be accessible for Azure ARM) to scriptURL
parameter ( "[parameters('scriptURL')]"
in "fileUris"
settings) which is already in your template.
CustomScriptExtension will download all files fileUris
into your VM to the extension folder, so you can use command as following:
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File install.ps1 '
Note:
You can find CustomScriptExtension logs and downloaded files in VM:
C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension
C:\Packages\Plugins
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.