Otter Documentation

powershell - PSExec

  • Last Modified: 2019-06-07

This is generated from the built-in components of Otter 2.2, and may be different than what you have installed (especially if you have extensions); go to [User Icon] > Documentation within your Otter instance to see exactly what operations are available.

PSExec

Executes a specified PowerShell script.

Operation type:

Executing - this operation will perform a specified action or actions on a remote server.

Script usage:

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

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

Arguments:

Name Format Script Usage Usage 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.

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);

Is this documentation incorrect or incomplete? Help us by contributing!

This documentation is licensed under CC-BY-SA-4.0 and stored in GitHub.