Trevor Sullivan
Trevor Sullivan17mo ago

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
2 Replies
rubenf
rubenf17mo ago
I think we will use this to integrate PowerShell officially Thanks for the Github discussion and post
Trevor Sullivan
Trevor SullivanOP17mo ago
It's not terribly elegant, but it does work. It would be nice to just write a script directly in the editor, rather than having to store it in a variable, download it, and then execute it.