find, loop through all windows servers??

Finally!!! After loading this site into several browsers I find one that allows me to TYPE my post!!! :slight_smile: :slight_smile: :slight_smile:

I don’t know where to find/get the old forums since I think I may have asked this already somewhere.

I want to get and loop through all the servers that PowerShell can find and know about – aka powered-on, check if it’s a Windows server like so:

This is PS 2.0 code, so:

$servers = $servers | foreach ($_name)

If Get-ADComputer - filter {operatingsystem -Like “Windows Server*”}

copy \$server\c$*changelog.txt \foo\backup

end if

next end for (I can find whatever it is that ends a for loop)

That’s the general code. Where I’m stuck is:

  1. constructing the for-each loop to get the servers

  2. testing the server

Do I have these parts correct??

Thank you, Tom

The old forums content was pulled over, so it’s here and searchable.

PowerShell uses C-like syntax. So you’re thinking…

$computers = Get-ADComputer -filter (whatever)
foreach ($computer in $computers) {
  if ($this -eq $that) {
    # do whatever

In terms of testing the server, it depends a bit. If your network is set up to allow a ping, you can run if (test-host $computer -quiet) { #do whatever } to ping the computer.

Thank you!! I found the archives once, I can find them again…
That general code snippet should get me started etc.
Thank you, Tom