Skip to content

Instantly share code, notes, and snippets.

@proxb
Created May 29, 2014 14:55
Show Gist options
  • Save proxb/140ba318c970464bf8f2 to your computer and use it in GitHub Desktop.
Save proxb/140ba318c970464bf8f2 to your computer and use it in GitHub Desktop.
Chained AddScripts()
$rs = [runspacefactory]::CreateRunspacePool(1,5)
$rs.Open()
$ps = [powershell]::Create()
$Ps.RunspacePool = $rs
[void]$ps.AddScript({
Write-Output 'Beginning Statement'
}).AddStatement().AddScript({
Param ($Name)
Get-Process -Name $Name
}).AddParameter('Name','PowerShell').AddStatement().AddScript({
Param($Param1,$Param2)
$DebugPreference = 'Continue'
Write-Debug "Param1: $Param1"
Write-Debug "Param2: $Param2"
}).AddParameters(@{Param1=10;Param2=500}).AddStatement().AddScript({
Write-Output 'End Statement'
})
$ps.Invoke()
$ps.Streams.Debug
$rs.Dispose()
$Ps.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment