DBThomson76
asked on
Powershell Script to reboot computer after I can ping it and it's online
I need a script to continuously ping a specific computer until it pings successfully and send a reboot command to reboot the same computer.
I know this is an odd request to reboot a computer when it first comes up but I need to do this to complete an install.
Any help is greatly appreciated.
I know this is an odd request to reboot a computer when it first comes up but I need to do this to complete an install.
Any help is greatly appreciated.
ASKER
Thank you!
Can it also tell me what date and time in rebooted?
Can it also tell me what date and time in rebooted?
Sure.
$targetname = "Server1"
do {
If(Test-Connection $targetname -Quiet){
shutdown /r /t 0 /f /m \\$targetname
Get-Date
}
sleep 5
} while ($true)
ASKER
I tried the script and it worked but if it is unattended it will reboot the computer again once it is back up.
I just need it to reboot once after it comes online.
Thanks!
I just need it to reboot once after it comes online.
Thanks!
Ok, we can do that too.
$targetname = "Server1"
$a = $true
do {
If(Test-Connection $targetname -Quiet){
shutdown /r /t 0 /f /m \\$targetname
Get-Date
$a = $false
}
sleep 5
} while ($a)
ASKER
Worked great.
Once last request. Can the date and time of when it rebooted be sent to a file for later review?
Thanks!
Once last request. Can the date and time of when it rebooted be sent to a file for later review?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked like a charm.
Thank you very much!!
Thank you very much!!
Glad to help. :)
ASKER
Thank you!
Great help
Great help
Open in new window
Just change to the server's name. This loop won't stop until you cancel it (ctrl+C).