Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How do I speed up this query by ignoring computers off the network faster?

$
0
0

Good afternoon,

I am running the below script to query the entire domain for local admins. Could anyone reccomend a way to speed this up by more quickly skipping computers that aren't on the network? Currently, every time it reaches a computer that is not on the network it hangs for up to 20 seconds (computers on the network return the data in less than a second). If I could decrease the ping time-out time, I could speed up this query tenfold.

Script pasted below - Thank you!!!

$Searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter = "(objectClass=computer)"
$Computers = ($Searcher.Findall())
md C:\Reports\IBX_Local_Admins_ALL
Foreach ($Computer in $Computers)
{
$Path=$Computer.Path
$Name=([ADSI]"$Path").Name
write-host $Name
$members =[ADSI]"WinNT://$Name/Administrators"
$members = @($members.psbase.Invoke("Members"))
$members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty',
$null, $_, $null) | out-file -append C:\Reports\IBX_Local_Admins_ALL\$name.txt
}





Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>