Run PowerShell With GitHub Actions

In this blog post, we will see how to run PowerShell commands and use variables inside a GitHub Actions Windows Server runner.


I have two steps in the workflow below, the first run basic Bash commands inside the runner (Ubuntu). In the second run, I am running two PowerShell commands. One of the commands is using a declared variable from the env section.

The PowerShell step is using a Windows Server 2019 runner and to access the variable I am using $env:VAR_NAME.

name: Run simple shell
on: [push]


    name: My first run
    runs-on: ubuntu-latest
      - name: Basic Bash shell command
          MYNAME: John
        run: |
         echo $MYNAME
        shell: bash 
    name: My second run
    runs-on: windows-latest
      - name: Basic PowerShell commands 
          MY_NAME: John Smith  
        run: |
           write-output $env:MY_NAME
        shell: powershell   

Below you can see the output from the second job that matches the above code.

For more articles about GitHub Actions please visit the category page.