Forum Discussion
Execute script on Azure Windows VM via Azure pipeline
Hi sag007,
There are several ways you could accomplish what you want:
1. Custom script VM extension - you could deploy a custom script VM extension as part of your VM provisioning (assuming you are using CLI, PowerShell, ARM/Bicep template or similar IaC tool for infra provisioning). You would add such an extension as a 'child resource' to your VM declaration. When the VM is fully up and running, this extension could trigger a PSH script to download and install your tool. Azure Custom Script Extension for Windows - Azure Virtual Machines | Microsoft Docs
2. State configuration - a feature of Azure Automation that is using PowerShell DSC to declare the 'desired state' of your VM. This indeed could be used as well, but it requires a bit of extra knowledge and steps to set it up, if you are not familiar with DSC. Azure Automation State Configuration overview | Microsoft Docs
3. Azure VM Run command - there is also a way to trigger an imperative command from "anywhere" (through the Azure Resource Manager API / control plane) without a need to either expose the VM to the Internet using a public IP or requiring a private connectivity for e.g., PowerShell Remoting. You could run this command from your pipeline agent. Run scripts in a Windows VM in Azure using action Run Commands - Azure Virtual Machines | Microsoft Docs
Depending where you could store the binary file (the tool) and the script, you might need to solve the topic of getting those files to the VM, e.g. by using a custom VM image and "bake the files" into the image, or storing the files in Azure Blob.
Hope it helps.