Search code examples
powershellazureazure-devopsrelease-management

How to Run Powershell Scripts on Azure VM between Tasks using Release Management (Team Services)


So I've successfully setup a Build and a Release in Team Services (previously VSO) and it's deploying the changes in my artifacts to my Azure VM's. So currently as part of one of the artifacts I am deploying to the Azure VM I'm releasing too, is a collection of Powershell scripts. So the tasks for the release looks somewhat like this:

  1. Deploy Powershell Scripts to Environment (Using Azure File Copy)
  2. Run one of the Powershell Scripts directly on that VM (Using Azure Powershell)
  3. Do the rest...

So for #2 above, I might be using the wrong type of task, I'm not sure (would love some guidance here). But how can I trigger a specific Powershell script to run that's on that specific VM so that it can access the file system of that VM.

For the Azure Powershell, I've tried setting the Powershell script location to what it should be on that VM, but no matter what it tells me it doesn't exist. I've also set it to the location of that Powershell script in the artifacts, in that case it finds it, but doesn't know anything about the file system I'm trying to access.

Is there something else I should be using to achieve running a Powershell script directly on a VM during a release?


Solution

  • Azure PowerShell task is not used to run the powershell script in Azure VMs, you need to use "PowerShell on Target Machines" task to run a script in a remote machine or Azure VM. Refer to this link for details: Deploy: PowerShell on Target Machines.