0

Azure DevOps has a UseDotNet@2 command which download and use specific/latest .NET Core runtime or SDK or both, the same function DevOps has for Python and Ruby.

This is very useful in case you have self-hosted agent, but there is no similar command for PowerShell (multiplatform PowerShell Core), eg. download and use latest PowerShell version, so I have to manage/upgrade PowerShell on self-hosted agents manually.

Is there any easy solution for implement this function?

4
  • "In MS DevOps" is too vague - if you're referencing something you do in the web console, please link to it or describe which steps you take to navigate to said interface Commented Apr 4 at 12:56
  • Not possible. The PowerShell task invokes powershell.exe or pwsh.exe depending on the pwsh input of the task. There is no input to manage the PowerShell version.
    – D1__1
    Commented Apr 4 at 20:05
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Apr 8 at 6:45
  • bryanbcook: give me the answer: "There isn't a built-in task to download and install a different version of PowerShell per run."
    – FErben
    Commented Apr 11 at 14:32

1 Answer 1

0

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.

1
  • Thank you, I know how call PowerShell and PowerShellCore commands. I thought I can install allways latest PowerShell per-run as I can in case "UseDotNet" command. Unfortunately as you wrote: "There isn't a built-in task to download and install a different version of PowerShell per run."
    – FErben
    Commented Apr 11 at 14:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.