Using the Inline PowerShell VSTS task

Run PowerShell in a VSTS pipeline from a textbox

The Inline PowerShell VSTS task enables you to execute PowerShell from a textbox within your build or release pipeline. You can run a PowerShell script on you agent or on Azure. The task can be installed from the Marketplace.

How to use the task

First add the task to you build or release pipeline. Select the +Add tasks -> Utility -> Run Inline PowerShell:

40 thoughts on “Using the Inline PowerShell VSTS task”

I am trying to use this task to trigger a WebJob as part of a build (using Invoke-RestMethod), however I always get the error “No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.”. I would have expected the task to have already selected the subscription based on the fact it is required as part of the configuration. Any ideas ?

@Dave what method do you use to login to azure? At logon it tries to select a subscription. Check if you have a default subscription for your Azure account. In the configuration of the task you do select the way you want to connect to Azure, not which subscription you connect to.

@Peter I use the “Azure Resource Manager” connection type and then select the appropriate subscription for the “Azure RM Subscription” option. I can see in the logs the following line, which i’m assuming is your task setting things up..

Hi Peter, I had to remove my call to Get-Website, i just could get it to work.

The reason I needed it was to extract the .PublishingUsername and .PublishingPassword properties so I could build the auth header for the Invoke-RestMethod. Instead I now just pass these as arguments to the script and it works – triggers my WebJob which in turn runs an executable on the remote Web App which has just been built and deployed.

I’m faced with the problem of wanting to forward a Team Build release description to iTunes Connect. The way this is done using the App Store Release task is by way of a file, and hence I found your extension task that could help me transform the $(Release.ReleaseDescription) variable into a text file on the file system. The idea is that I could then use this file as input to the App Store Release task, in order to pass on “what to test?”.

Unfortunately, however, although PowerShell seems capable of escaping quotation marks passed in variables on the command line (i.e. first define the variable with quotation marks in it, then execute a script using this variable as a parameter), it does not seem to do so for your task. Hence, since I escape my $(Release.ReleaseDescription) by enclosing it in double quotes, using double quotes in the latter value breaks the script and – therefore – the release.

Is there anything I can do to correct or prevent this problem from occurring? It would be really nice to have this functionality, as we would then have a single point of reference of what would have been passed on to iTunes Connect.

Hi,
I was using this task as part of my release definition to stop website in IIS with the following script:
Invoke-Command -ComputerName TargetServer -ScriptBlock {Import-Module WebAdministration; Stop-Website -Name “Websitename”}
And I am getting error stating “Connecting to remote server “xyz” failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting”.
Made sure that PSRemoting is enabled and also the WsMan is running.
However, when I run the same script directly from Powershell, it works.
Any thoughts please.

I’ll throw out there that that is machine and user specific. You might want to ensure you’ve created this file with the exact same user and on the box itself before trying to Import the contents and resuse. I’ve successfully done this but with the caveats mentioned.

Is it possible to change the values of Build/Release variables in an Inline Azure Powershell Script to have that ‘new’ value available in a later Build/Release step?
I am trying to retrieve the Key from my Application Insights instance so that I can inject it into my UI code at release time ( using Replace Token task).

In the Microsoft provided “Azure Powershell” task, I can do this:
##vso[task.setvariable variable=OutputVar;]UpdatedValueInScript

2017-12-06T17:27:21.9374726Z ##[error]The term ‘Name[0]:’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

So it looks like Install-Module is found ok, but it doesn’t seem to take my module name as it seems to be asking for Name.

Howdy! Your extension makes my life so much easier, but I wonder if there’s a way to disable the splash screen text and tips that precede every inline script’s output? It clutters up the log file and makes it hard to see the actual results.

Im trying to use Inline Powershell utilizing powershell core, however no matter what I try (configured agent machine registry to use pwsh as default shell, added PowerShell 6.1.0 as system variable so agent wuld use it), it will revert back to using powershell 5.1. Is powershell core supported and if it is, how can I change Inline Powershell to use it?

The task is started by the VSTS build agent. I guess it uses the 5.1 for backward compatibility. You can add an issue in the GitHub repo, I’ll accept PRs. When I do have the time or find a fix I’ll do an update.

Inline Powershell exposes passwords in temporary PS1 file on build server.
We have our own build servers hosted on Azure VM. The issue with inline powershell is… it copies the powershell to temporary location on build server. And even when password is stored as secret on VSTS and we also ConvertTo-SecureString. But in the copied temporary location it is stored as text in the temp/xyz.ps1 file. NOT SECURE.