Think I've got this working for the most part, does the reboot part fine anyway, but the output to host is a bit messy. Really I just want it to reboot it or tell me "computer is not online". I can always go find out why it's not online if it's a concern some other way later.
###Puts all Non-Server computers in a variable using their dnshostname
$computers = Get-ADComputer -Filter {OperatingSystem -NotLike "*server*"} -Properties operatingsystem | foreach { $_.DNSHostName }
###Tests Connection to $computers and restarts any up $computers
foreach ($computer in $computers)
{
$connected = test-connection $computer -count 1 -Quiet
if ($connected)
{
Restart-Computer -ComputerName $computer -Force}
}
else {
write-host "$computer is not online"
}
Computers restart as they should (save for one with some RPC issue I can't sort out - not the usual suspects of Firewall, RPC service, etc), but the ones that are offline, I get row after row of:
Restart-Computer : Failed to restart the computer computer23.domain.local with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).
Also get this which I assume is because by the time it loops through restart-computer it has no idea what I"m "else"ing:
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:21 char:9
+ else {
+ ~~~~
+ CategoryInfo : ObjectNotFound: (else:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException