Last active
November 8, 2017 15:13
-
-
Save rodmhgl/d119bf41a0b66371a864f3ba887d1096 to your computer and use it in GitHub Desktop.
Quick PowerShell Jobs Demo
This file contains 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
# 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