DEV Community

Jesse Houwing for Xebia Microsoft Services

Posted on • Originally published at jessehouwing.net on

Upgrade Hosted Agent / GitHub Runner PowerShell

Upgrade Hosted Agent / GitHub Runner PowerShell

I managed to upgrade PowerShell at the start of the run and the agent will happily use it after installation.

You need to do two simple things.

  1. Install the PowerShell Core Preview onto the agent.
  2. Make PowerShell Core Preview the default by prepending the PATH environment variable.

Once you know how, it's easy:

- run: |
    Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -preview -quiet"
    "C:\Program Files\PowerShell\7-preview" >> $env:GITHUB_PATH
  name: Upgrade to latest preview of powershell 
  # https://github.com/PowerShell/PowerShell/issues/17404#issuecomment-1188348379
Enter fullscreen mode Exit fullscreen mode

The same trick would work on Azure Pipelines:

- pwsh: | 
    Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -preview -quiet"
    write-host "##vso[task.prependpath]c:\Program Files\PowerShell\7-preview"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)