Skip to main content

PowerShell Script

icon
PowerShell Script (.ps1)

Allows you to execute a PowerShell (.ps1) script in a Windows environment.

Code

The code of the PowerShell script to execute. Variables can be used in this script and will be replaced before executing

# This is a template PowerShell script

# Replace {file.FullName} and {file.Orig.FullName} with actual values
$WorkingFile = '{file.FullName}'
$OriginalFile = '{file.Orig.FullName}'

# Example commands using the variables
Write-Output "Working on file: $WorkingFile"
Write-Output "Original file location: $OriginalFile"

# Example: Modify the filename and set it as the new working file for subsequent flow elements
$NewFilePath = $WorkingFile -replace '\.mp4$', '_edited.mp4'
Rename-Item $WorkingFile $NewFilePath

# Set the new working file for the flow
SetWorkingFile($NewFilePath)

# Add your actual PowerShell commands below
# Example: Copy the working file to a backup location
# Copy-Item -Path $NewFilePath -Destination "C:\Backup\$([System.IO.Path]::GetFileName($NewFilePath))"

# Set the exit code to 1
exit 1

Set Working File

You can update the file that will be used by the next flow element in your flow using the SetWorkingFile() function.

SetWorkingFile("C:\path\to\newfile.mp4")
  • No need to manually Write-Output "SETWORKINGFILE=...".
  • Only the last call to SetWorkingFile() in the script will be applied.
  • This allows you to rename, move, or otherwise modify files while ensuring downstream flow elements use the correct file.

Example usage:

# Rename working file
$NewFile = $WorkingFile -replace '\.mp4$', '_compressed.mp4'
Rename-Item $WorkingFile $NewFile

# Tell the flow to use the new file
SetWorkingFile($NewFile)

Exit Codes

NumberDescription
1+Specifies which output is to be called. Define the number of outputs using the Outputs field. This will add more output connections to the flow element.
0Completes the flow successfully. This will immediately stop the flow and mark it as successful.
otherIf a number is returned that is outside the range of defined outputs, this will mark the flow as unsuccessful.

Examples

Steam Gaming Running

This script will test if steam is running and if there is a child-process. Its not a fool proof way of detecting if a game is running, but its a start

# Define the Steam process name and pattern to identify Steam-related processes
$steamProcessName = "steam"
$steamGameProcessPattern = "*steam*"

# Get the list of running processes
$runningProcesses = Get-Process

# Check if Steam is running
$steamRunning = $runningProcesses | Where-Object { $_.Name -eq $steamProcessName }

if ($steamRunning -eq $false) {
Write-Output "Steam is not running."
exit 1 # Exit with code 1 if Steam is not running
}

# List all running processes that are likely Steam games
$steamGameProcesses = $runningProcesses | Where-Object { $_.Path -like $steamGameProcessPattern }

if ($steamGameProcesses.Count -gt 0) {
Write-Output "Steam is running and the following Steam-related processes (likely games) are currently running:"
$steamGameProcesses | ForEach-Object { Write-Output $_.Name }
exit 0 # Exit with code 0 if Steam games are running
} else {
Write-Output "Steam is running, but no associated processes (likely games) are found."
exit 1 # Exit with code 1 if no Steam games are running
}