Skip to content

Instantly share code, notes, and snippets.

@santisq
Created January 7, 2022 01:05
Show Gist options
  • Save santisq/d790ea1814e1f2de8c7b457df0003c10 to your computer and use it in GitHub Desktop.
Save santisq/d790ea1814e1f2de8c7b457df0003c10 to your computer and use it in GitHub Desktop.
a very basic Runspace blueprint
$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