I would like to use a custom script extension on a windows VM to automatically run two powershell commands after deployment. I have tried using the following extension: https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
But in "commandToExecute"
I would like to enter both powershell commands directly and not through a .ps1 file.
The bicep code is as following:
resource extension 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
parent: windowsvm
name:'config-app'
location:location
properties:{
publisher: 'Microsoft.Compute'
type:'CustomScriptExtension'
typeHandlerVersion: '1.10'
autoUpgradeMinorVersion: true
protectedSettings:{
commandToExecute: 'powershell -command "Install-Module -Name XXXX -AllowClobber -Force; Install-Module -Name XXXX -AllowClobber -Scope CurrentUser -Force"'
}
}
}
But the deployment is currently in an endless loop. Any ideas how I can pass both commands directly?
Thanks!
CodePudding user response:
As most of the powershell commands are run in the form of powershell script with .ps1 file extension in bicep/ ARM template , deployments will be successfull as our local machines has the installed powershell modules in the machine.
As in the Azure VM, the nugets may not be present by default. So as mentioned by AzUser1, one may need to install the required nugets to use the commands directly in the template.