Some tasks within Azure DevOps bake the version into the task. For example, the AzurePowerShell@5
task has an input parameter that lets you specify the Azure PowerShell version. If the version isn't present, it will download it.
Regarding Windows PowerShell (5.x) versus PowerShell Core (7.x), the latest versions are bundled on the Microsoft provided build agents. It is generally recommended to use the latest version as they are full featured, backward compatible and patched with the latest security fixes. If you're using a self-hosted agent, you may need to update your build agent image with the latest version.
You can differentiate between Windows PowerShell and PowerShell Core using the pwsh
input parameter.
steps:
- task: PowerShell@2
displayName: 'PowerShell Core'
inputs:
targetType: inline
script: |
Write-Host "PowerShell!"
pwsh: true # PowerShell Core
- task: PowerShell@2
displayName: 'Windows PowerShell'
inputs:
targetType: inline
script: |
Write-Host "PowerShell!"
pwsh: false # Default
Note that you can use pwsh
as an alias for PowerShell Core.
steps:
- pwsh: |
Write-Host "hello world!"
displayName: 'PowerShell Core'
There isn't a built-in task to download and install a different version of PowerShell per run.
PowerShell
task invokespowershell.exe
orpwsh.exe
depending on thepwsh
input of the task. There is no input to manage the PowerShell version.