API Reference
Class
PowerShellExecutionEnvironment
Provides a configured PowerShell runspace with required modules loaded.
Inheritance
- Object
- PowerShellExecutionEnvironment
Remarks
This class manages a runspace and imports modules so that cmdlets can be executed without worrying about dependencies.
Examples
using var env = new PowerShellExecutionEnvironment(new PowerShellModuleManager());
using PS ps = await env.CreateConfiguredPowerShellAsync(new[] { "DnsServer" }, CancellationToken.None);
Constructors
public PowerShellExecutionEnvironment(PowerShellModuleManager moduleManager) #Initializes a new instance of the PowerShellExecutionEnvironment class.
Parameters
- moduleManager TestimoX.PowerShell.PowerShellModuleManager
- Module manager used to load dependencies.
Methods
public async Task<PowerShell> CreateConfiguredPowerShellAsync(String[] requiredModules, CancellationToken cancellationToken) #Returns:
Task<PowerShell>Creates a PowerShell instance with modules imported.
Parameters
- requiredModules System.String[]
- cancellationToken System.Threading.CancellationToken
Examples
using PS ps = await env.CreateConfiguredPowerShellAsync(requiredModules, CancellationToken.None);
ps.AddCommand("Get-Process");
var results = await ps.InvokeAsync();
public virtual Void Dispose() #Returns:
Void