0

Why, in the code below, does the Read-Host line's output display before the job's output?

$WorkingDirectory = Get-Location

$ScriptBlockForJob = {    
    Get-ChildItem $Input -Directory `
        | Where-Object `
            {$_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0} `
                | Select-Object FullName                
}

Start-Job -InputObject $WorkingDirectory -ScriptBlock $ScriptBlockForJob | Wait-Job | Receive-Job 

Read-Host 'Above is a list of empty directories. Press enter to begin deleting them'

The code above yields this ouput

derekbaker783
  • 8,109
  • 4
  • 36
  • 50

1 Answers1

0

If instead you remove the last line in $ScriptBlockForJob, the command will run as expected.

$ScriptBlockForJob = {    
    Get-ChildItem $Input -Directory `
        | Where-Object `
            {$_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0}                               
}

Output as expected

derekbaker783
  • 8,109
  • 4
  • 36
  • 50