Hello All,
I am looking into some help modifying a script I found on this site. I really need to combine two scripts. I am looking to query active directory for a list of computers that are "Like" ivprd-p*. I then want to take that list and reboot the computers. These are Remote Desktop servers that I would like to reboot nightly. Reboot-Computer will not complete if the server has users on it when the command is executed which is what I want (So I don't bounce users off of it). So, I would like to run the below but add in an email receipt of the outcome. I would like to know whether or not the reboot was successful. The script over here is close, but when I tested it the results only indicated the command was successfully sent to the server. The failure output looks like this and it is what I would like to key on as to whether or not the server was rebooted.
PS C:\Users\adminjf> Restart-Computer -computername ivprd-p196v
Restart-Computer : Failed to restart the computer ivprd-p196v with the following error message: The system shutdown
cannot be initiated because there are other users logged on to the computer.
$computers= (Get-ADComputer-Filter { Name-like"ivprd-p*" }).Nameforeach ($computerin$computers) {Restart-Computer-ComputerName$computer }
I appreciate any help or advice you all can offer :: Cheers