Author Posts

June 10, 2013 at 10:05 am

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

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

June 10, 2013 at 10:58 am

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.

June 10, 2013 at 12:48 pm

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