In this blog post, we will see how to run PowerShell commands and use variables inside a GitHub Actions Windows Server runner.
Workflow
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] jobs: linux_run: name: My first run runs-on: ubuntu-latest steps: - name: Basic Bash shell command env: MYNAME: John run: | date uname echo $MYNAME shell: bash windows_run: name: My second run runs-on: windows-latest steps: - name: Basic PowerShell commands env: MY_NAME: John Smith run: | get-date 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.