Powershell jobs

Mostly for my own benefit but maybe someone will find this a helpful and concise reference

Create a job like this
$job = start-job {sleep 60; get-service;}

If you’re creating jobs in a loop, add them to an array
$jobs = @()
foreach ($asdf in $qwer) { $jobs += start-job {…} }

Check job status while a job is running with
$job | get-job

Receive the result of that job with
$jobResult = ($job | wait-job | receive-job)

To execute some command over a large number of servers:

$creds = get-credential

$scriptBlock = {
    write “running on $server”;
    Invoke-Command -ComputerName $server -Credential $creds -Command {
        & {get-childitem -Path ‘C:' -Filter ‘whatever’ -Recurse } 2>$null 3>$null

$servers = @(“server1”, “server2”, “server3”, “etc”)
$servers | % {
    start-job -ScriptBlock $scriptBlock -ArgumentList $_,$creds