How do I write an inline multiline powershell script in an Azure Pipelines PowerShell task? How do I write an inline multiline powershell script in an Azure Pipelines PowerShell task? powershell powershell

How do I write an inline multiline powershell script in an Azure Pipelines PowerShell task?


You can use the pipe character (the literal Block Scalar Indicator) to define a multi-line block of text with newline characters such as your inline script; for example like this:

- task: PowerShell@2  inputs:    targetType: 'inline'    script: |      # Write your PowerShell commands here.      Write-Host "Hello world"      Write-Host "Hullo clouds"      Write-Host "Hullo sky"


It is possible to just use the powershell task like this:

# Job definition etcsteps:  - powershell: |      Write-Host A      Write-Host B      Write-Host C  - task: AzureRmWebAppDeployment@4      # The rest of this task is omitted.

If you use powershell instead of task: PowerShell@2 the target type defaults to inline and you don't need to set it again.


It's possible to chain PowerShell command using semicolon. So in effect writing several commands on one line, separated by semicolon.

(Be aware of the 5000 characters line limit in Azure Pipelines.)