Trevor SullivanT
Windmill3y ago
3 replies
Trevor Sullivan

How can I run a PowerShell script inside Windmill?

1. Create a Bash script
1. Install PowerShell if not installed (see snippet below)
1. Store PowerShell script in Windmill variable
1. Retrieve variable value and write to file
1. Execute script

Install PowerShell Debian Package (if not already)

which pwsh > /dev/null
if [ $? -ne 0 ]
then
echo 'Downloading PowerShell package'
  export DOWNLOAD_URL='https://github.com/PowerShell/PowerShell/releases/download/v7.3.5/powershell_7.3.5-1.deb_amd64.deb'
  export FILE_NAME='pwsh.deb'
  wget -O $FILE_NAME $DOWNLOAD_URL
  dpkg --install $FILE_NAME
  rm $FILE_NAME
fi


Grab PowerShell Script From Variable and Store in File

curl -s -H "Authorization: Bearer $WM_TOKEN" \
  "$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/variables/get/u/trevor/aws_s3_delete_bucket" \
    | jq -r .value > script.ps1


Invoke the PowerShell Script

pwsh -File script.ps1
Was this page helpful?