Restar-computer wait for next command

Hi, in a script i want to restart  a server and wait until the server is up to run the next command.

I know that in POSH 3 i can use -wait but i need to use POSH 2

What is the best way? 

Restart-Computer  -ComputerName $svr  -AsJob

Thanks

August 5th, 2013 11:26am

do a test-connection $srv this will tell you when pc is pinging from there run your command..

if(test-connection $svr){
your next step
{


Free Windows Admin Tool Kit Click here and download it now
August 5th, 2013 11:29am

Hi, 

I thought about that, but that will get me true or false..

If it is false will it keep doing it until it gets true and then move on?

August 5th, 2013 11:45am

Hi,

Take a look at this thread, it has several snippets that will help you:

http://social.technet.microsoft.com/Forums/scriptcenter/en-US/e5dd32bc-33d0-41fb-9f2d-ad45ff4b091e/multiple-servers-reboot-conditional

Free Windows Admin Tool Kit Click here and download it now
August 5th, 2013 11:49am

You could do a endless loop until the server is up again

Restart-Computer $server

Do { Sleep 10 # Sleep for 10 secs, then test ping }While (Test-Connection $server)

The only issue I see is, you can get a successful ping, even if the server isn't fully up, and still booting. So depending on your next tasks, they may or may not run corre
August 5th, 2013 12:10pm

yeah you can do while loop, sometimes you have to query some services such as winrm to make sure server is fully back up before you can perform a remote command or somethign
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2013 12:22pm

You could do a endless loop until the server is up again

Restart-Computer $server

Do { Sleep 10 # Sleep for 10 secs, then test ping }While (!(Test-Connection $server))

The only issue I see is, you can get a successful ping, even if the server isn't fully up, and still booting. So depending on your next tasks, they may or may not run corre
August 5th, 2013 7:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics