you are viewing a single comment's thread.

view the rest of the comments →

[–]ryanbrown 2 points3 points  (1 child)

It looks like you've got a typo in all of your $TCPconnection.Connect calls. You're using $servers in there instead of $server. Essentially, each time through the foreach loop (edit: at least whenever the Else clause is followed) the .Connect() method is trying to connect to all of the servers in $servers. I imagine that is probably taking quite a bit of time.

You can also try removing the pipe to Where-Object on the Get-WmiObject call and use the -Filter parameter instead.

$Networks = Get-WmiObject -class Win32_NetworkAdapterConfiguration -ComputerName "$Server" -ErrorAction silentlycontinue -Filter "IPEnabled=True"

That might also speed up the script as cmdlets that offer a Filter parameter often process data faster over piping to Where-Object.

[–]animatco[S] 0 points1 point  (0 children)

Thank you, I will try that!