I want to test for the existence of a file path on many computers, using SMB. Many of these computers will be offline, and it takes several seconds for the SMB request to time out, so I want to run this command in parallel. Foreach -parallel, however, does not seem to be running in parallel. It seems to just go one computer at a time, running no faster than regular foreach.
This code gets a list of recently-logged-into computers. It then records whether the path \\$computer\users\foo\ exists on each of those computers.
workflow Find-FoosComputer
{
$computers = Get-Adcomputer -filter * -properties name,LastLogon | where {$_.lastlogon -ne $NULL} | where {[datetime]($_.lastlogon) -le (get-date).AddDays(-14)}|select -expandproperty name
foreach -parallel ($computer in $computers){
($computer, (Test-Path "\\$computer\users\foo\")) > "c:\temp\results.txt"
}
}
What can I do to get foreach -parallel to actually run in parallel, and run test-path on all the computers at once?