开发者

Is there a Powershell Get-Childitem timeout property?

开发者 https://www.devze.com 2023-02-05 00:11 出处:网络
I am trying to use the GCI cmdlet to get information on many remote computers, some of which are sometimes turned off or unresponsive. Is there a way I can specify a timeout property for get-childitem

I am trying to use the GCI cmdlet to get information on many remote computers, some of which are sometimes turned off or unresponsive. Is there a way I can specify a timeout property for get-childitem so that the s开发者_StackOverflowcript doesn't hang for 15-20 seconds every time it hits an unresponsive computer?

Thanks,

Tomek


Do your work in a job, then wait on it using wait-job (which has a timeout argument):

$job = Start-Job {Sleep -seconds 60}
$res = Wait-Job $job -timeout 5
if(-not $res) { write-Host "Timeout"}


Or wrap your gci in test-connection

if (test-connection $server -quiet){ gci }
else {"Connect failed to $server"}

0

精彩评论

暂无评论...
验证码 换一张
取 消