I need to access underlying powershell default Pipeline which just created as result of Pwoershell.Create();
I need to stop that pipeline so that script execution must stopped immediately.
I know I can Create Pipeline object and execute script by calling pipeline.Invoke(). But Pipeline object not giving me all Data streams which is being provided by Powershell instance.
powerShellInstance = PowerShell.Create();
powerShellInstance.Runspace = RunspaceFactory.CreateRunspace(iss)
Later some point I need
powerShellInstance.GetPipeline().Stop() // something like this.
Is there any thing by which I can achieve this?
Edit
For example I have following script.
Set-LinkParameter"withError" => This commandlet will throw error
Set-LinkParameter11 "Mistyped" "error" => Powershell will throw an error of invalid commandlet
Initialiize-Access => this is invalid here and this commandlet will throw error. Here it must not allow further script to execute.
Write-Host "This is test message for host"
Write-Information "test information"
Write-Error "Access denied." --> this is can be terminating error ( depends)
Write-Warning "This is test warning."
Write-Verbose "This is verbose message"
Write-Verbose "This is verbose message" -Verbose
Write-Debug "Test Debug message" -Debug
Write-Debug "wont appear at debug pipeline"
Write-Output @(1,2,3) -NoEnumerate | measure
Edit (Async Stop) before in the code..
powerShellInstance.Streams.Error.DataAdded += OnError
OnError(sender,event)
{
//this would have been invoked asyncronously.
powerShellInstance.BeginStop(null,null);
}