Table of Contents

Class PowershellRunner

Namespace
SunamoPS
Assembly
SunamoPS.dll

Core PowerShell command runner that executes commands and returns structured output.

public class PowershellRunner : PsOutput
Inheritance
PowershellRunner
Inherited Members
Extension Methods

Properties

Instance

Singleton instance of PowershellRunner.

public static PowershellRunner Instance { get; }

Property Value

PowershellRunner

ProgressState

Gets or sets the progress state for tracking command execution.

public ProgressStatePS ProgressState { get; set; }

Property Value

ProgressStatePS

SaveUsedCommandToDictionary

Gets or sets whether executed commands should be saved to a dictionary.

public bool SaveUsedCommandToDictionary { get; set; }

Property Value

bool

UsedCommandsInFolders

Gets or sets the dictionary of used commands mapped by folder path.

public Dictionary<string, List<string>> UsedCommandsInFolders { get; set; }

Property Value

Dictionary<string, List<string>>

Methods

Invoke(List<string>, PsInvokeArgs?)

Invokes a list of PowerShell commands and returns structured output. For each command, returns at least one entry in the result.

public Task<List<List<string>>> Invoke(List<string> commands, PsInvokeArgs? invokeArgs = null)

Parameters

commands List<string>

List of PowerShell commands to execute.

invokeArgs PsInvokeArgs

Optional invocation arguments for caching, progress, and command prepending.

Returns

Task<List<List<string>>>

List of output lists, one per command.

InvokeInFolder(string, string)

Invokes a command in a specified folder by first changing directory. The cd command output is excluded from results, so index [0] contains the actual command output.

public Task<List<string>> InvokeInFolder(string folder, string command)

Parameters

folder string

Folder to change to before executing the command.

command string

Command to execute in the folder.

Returns

Task<List<string>>

List of output lines from the command.

InvokeLinesFromString(string, bool)

Invokes commands parsed from a multi-line string and returns the combined output as lines.

public Task<List<string>> InvokeLinesFromString(string text, bool isWritingProgressBar)

Parameters

text string

Multi-line string containing commands.

isWritingProgressBar bool

Whether to write progress bar updates.

Returns

Task<List<string>>

List of output lines.

InvokeProcess(string, string, InvokeProcessArgsPS?)

Invokes an external process and returns its standard output as a list of lines. If the exe file name does not contain an extension, .exe is appended automatically. The file name must not be a full path, only the executable name.

public Task<List<string>> InvokeProcess(string exeFileNameWithoutPath, string arguments, InvokeProcessArgsPS? processArgs = null)

Parameters

exeFileNameWithoutPath string

Executable file name without full path.

arguments string

Command-line arguments for the process.

processArgs InvokeProcessArgsPS

Optional process invocation arguments (e.g., working directory).

Returns

Task<List<string>>

List of output lines from the process.

InvokeSingle(string)

Invokes a single PowerShell command and returns its output.

public Task<List<string>> InvokeSingle(string command)

Parameters

command string

Command to execute.

Returns

Task<List<string>>

List of output lines from the command.