如何使整个networking更快的PowerShell文件search

我试图searchADnetworking中所有机器上的所有驱动器,我的方法效率不高。 基本上,我想出了这样一个脚本,它是这样做的:

  1. 从AD获取所有计算机。
  2. 检查是否有WMI连接,logging机器,以便我可以照看。
  3. 获取计算机上的所有物理驱动器。
  4. search远程共享上的文件

$computers = Get-ADComputer -filter * | Select -Exp Name $computers.Count $i = 0 foreach ($computer in $computers) { $i++ Write-Host "Checking Computer Number " $i " with the hostname " $computer if (Test-Connection $computer -Quiet ) { $drives = get-wmiobject -computer $computer win32_logicaldisk -filter "drivetype=3" | select -Exp DeviceID foreach ($drive in $drives) { $drive = $drive.Substring(0,$drive.Length-1) + "$" Get-ChildItem -Recurse -Force \\$computer\$drive -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and ( $_.Extension -eq ".crypt") } | Select-Object Name,Directory| Export-Csv C:\FoundFiles.csv -nti -append } } else { $computer >> C:\OfflineComputers.txt } } 

问题在于这是非常低效和缓慢的。 这可能需要数周的时间才能完成,这个networking包括150多台服务器和50多个客户端。

你觉得我怎么能让这个跑得更快? 用“Invoke Command”发送一个命令给每个服务器工作吗? 我不需要实际的代码来做,只是一个方向就足够了。