Created
January 7, 2022 01:05
-
-
Save santisq/d790ea1814e1f2de8c7b457df0003c10 to your computer and use it in GitHub Desktop.
a very basic Runspace blueprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Action = { } | |
try { | |
$iss = [initialsessionstate]::CreateDefault2() | |
$rs = [runspacefactory]::CreateRunspace($Host, $iss) | |
$rs.Open() | |
$ps = [powershell]::Create() | |
$ps.Runspace = $rs | |
$ps.AddScript($Action).Invoke() | |
foreach ($e in $ps.Streams.Error) { | |
# non-terminating error here | |
$e | |
} | |
} | |
catch { | |
# terminating error here | |
} | |
finally { | |
if ($null -ne $ps) { | |
$ps.Dispose() | |
} | |
if ($null -ne $rs) { | |
$rs.Dispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment