Skip to content

Instantly share code, notes, and snippets.

@rodmhgl
Last active November 8, 2017 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodmhgl/d119bf41a0b66371a864f3ba887d1096 to your computer and use it in GitHub Desktop.
Save rodmhgl/d119bf41a0b66371a864f3ba887d1096 to your computer and use it in GitHub Desktop.
Quick PowerShell Jobs Demo
# functions.ps1 contains functions like Get-Services, Get-Process,
# Get-CustomFunction1, Get-CustomFunction2, etc. that execute
# locally on the remote computer. Output is ex
function Get-CustomFunction {
sleep 2
write-output $true
}
$GetProcess = Start-Job -ScriptBlock { Get-Process }
$GetCustomFunction = Start-Job -ScriptBlock { Get-CustomFunction }
$GetService = Start-Job -ScriptBlock { Get-Service }
wait-job -Job $GetProcess, $GetCustomFunction, $GetService
$ProcessResults = Receive-Job -Keep -Job $GetProcess
$CustomFunctionResults = Receive-Job -Keep -Job $GetCustomFunction
$ServiceResults = $GetService | receive-job -Keep -Job $GetService
remove-job -Job $GetProcess, $GetCustomFunction, $GetService
# Here you could create custom objects for output, etc...
# Or just output to xml / csv
$ProcessResults | Export-Clixml c:\temp\ExportedProcesses.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment