Calvindd2f / executor

2 stars 0 forks source link

Summary

The PowershellExecutor class is designed to execute PowerShell scripts and handle various types of output logs such as verbose, warning, error, and information. It binds to PowerShell streams to capture and process these logs, sending them to a native logging function via P/Invoke. The class also includes mechanisms to handle activity log thresholds and specific error details, such as web exceptions.

Build

mkdir build cd build cmake ..

Example Usage

IntPtr callbacks = // obtain the callback pointer
PowershellExecutor executor = new PowershellExecutor(callbacks);

PowerShell ps = PowerShell.Create();
DefaultHost host = new DefaultHost();

executor.BindEvents(ps, host);

string script = "Get-Process";
bool isInlinePowershell = true;

try
{
    PowerShellExecutionResult result = executor.ExecutePowerShell(script, isInlinePowershell);
    // Process result
}
catch (NotImplementedException ex)
{
    Console.WriteLine(ex.Message);
}

Code Analysis

Main functionalities