Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

PSExec

Executes a specified PowerShell script.

Script usage:

Execute-PowerShell(
	Text: <text>,
	[Debug: <true/false>],
	[Verbose: <true/false>],
	[RunOnSimulation: <true/false>],
	[Isolated: <true/false>],
	[SuccessExitCode: <text>],
	[PreferWindowsPowerShell: <text>]
);

This operation may be prefixed with PowerShell::, although this is a built-in namespace and isn't really necessary.

Arguments:

NameFormatScript UsageUsage Notes
Script contents (default)
text
Text
The PowerShell script text. Variables are not expanded within the contents of this property. This argument is required.
Capture debug
true/false
Debug
Captures the PowerShell Write-Debug stream into the Otter debug log. The default is false.
Capture verbose
true/false
Verbose
Captures the PowerShell Write-Verbose stream into the Otter debug log. The default is false.
Run on simulation
true/false
RunOnSimulation
Indicates whether the script will execute in simulation mode. The default is false.
Isolated
true/false
Isolated
When true, the script is run in a temporary AppDomain that is unloaded when the script completes. This is an experimental feature and may decrease performance, but may be useful if a script loads assemblies or other resources that would otherwise be leaked.
Success exit code
text
SuccessExitCode
Integer exit code which indicates no error. The default is empty, treating all exit codes as success. This can also be an integer prefixed with an inequality operator.
Prefer Windows PowerShell
text
PreferWindowsPowerShell
When true, the script will be run using Windows PowerShell 5.1 where available. When false or on Linux (or on Windows systems without PowerShell 5.1 installed), the script will be run using PowerShell Core instead.

Note: This operation will inject PowerShell variables from the execution engine runtime that match PowerShell variable expressions. This means you won't get an error if you use an undeclared variable in your script, but some expressions that PowerShell interoplates at runtime (such as a variable inside of a string), cannot be replaced by the operation.

Note: If you are attempting to write the results of a Format-* call to the log, you may see messages similar to "Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData". To convert this to text, use the Out-String commandlet at the end of your command chain.

Note: This script will execute in simulation mode; you set the RunOnSimulation parameter to false to prevent this behavior, or you can use the $IsSimulation variable function within the script.

Example:


# writes the list of services running on the computer to the Otter log
psexec >>
    Get-Service | Where-Object {$_.Status -eq "Running"} | Format-Table Name, DisplayName | Out-String
>>;

# delete all but the latest 3 logs in the log directory, and log any debug/verbose messages to the Otter log
psexec >>
    Get-ChildItem "E:\Site\Logs" | Sort-Object $.CreatedDate -descending | Select-Object -skip 3 | Remove-Item
>> (Verbose: true, Debug: true, RunOnSimulation: false);