WindmillWWindmill
Powered by
Trevor SullivanT
Windmill•3y 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
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
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
pwsh -File script.ps1
WindmillJoin
3,362Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Recent Announcements
henri-c

Weekly kenote to tell you about our latest updates https://discord.com/channels/930051556043276338/1278977038430240813 https://youtube.com/live/2dGd9TdT8xs?feature=share

henri-c · 4d ago

Pyra

### HTTP tracing (EE) Capture HTTP requests made by job scripts as observability spans Features: - View HTTP request traces (method, URL, status, timing) in the job details UI - Auto-instrumentation for Native TypeScript, MITM proxy for other languages - Integrates with external OpenTelemetry collectors changelog: https://www.windmill.dev/changelog/http-tracing docs: https://www.windmill.dev/docs/advanced/instance_settings#http-tracing Additionally jobs memory metrics are now fully OSS!

Pyra · 2w ago

henri-c

First keynote of the year here https://discord.com/channels/930051556043276338/1278977038430240813 🙂

henri-c · 4w ago

Similar Threads

AD Module - Windmill Powershell
XseamXXseam / help
14mo ago
Trying to understand Windmill+Powershell
bohitiBbohiti / help
13mo ago
Test powershell script on worker
AlainAAlain / help
6mo ago
Native script editor for PowerShell
Trevor SullivanTTrevor Sullivan / help
3y ago