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
ProgressState
Gets or sets the progress state for tracking command execution.
public ProgressStatePS ProgressState { get; set; }
Property Value
SaveUsedCommandToDictionary
Gets or sets whether executed commands should be saved to a dictionary.
public bool SaveUsedCommandToDictionary { get; set; }
Property Value
UsedCommandsInFolders
Gets or sets the dictionary of used commands mapped by folder path.
public Dictionary<string, List<string>> UsedCommandsInFolders { get; set; }
Property Value
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
commandsList<string>List of PowerShell commands to execute.
invokeArgsPsInvokeArgsOptional invocation arguments for caching, progress, and command prepending.
Returns
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
folderstringFolder to change to before executing the command.
commandstringCommand to execute in the folder.
Returns
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
textstringMulti-line string containing commands.
isWritingProgressBarboolWhether to write progress bar updates.
Returns
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
exeFileNameWithoutPathstringExecutable file name without full path.
argumentsstringCommand-line arguments for the process.
processArgsInvokeProcessArgsPSOptional process invocation arguments (e.g., working directory).
Returns
InvokeSingle(string)
Invokes a single PowerShell command and returns its output.
public Task<List<string>> InvokeSingle(string command)
Parameters
commandstringCommand to execute.