Tibo64
Contributor
Contributor

Powercli script start vm and check boot

Jump to solution

Hi,

I try to make a powercli script to start vm and check when the os (windows) is completely booting and ready .

How i can do that ?

1 Solution

Accepted Solutions
naiksidd
Enthusiast
Enthusiast

may be this helps..

Start-vm -VM <Name> -runAsync

$vm = get-vm <name>

Start-Sleep -Seconds 20;

$vm  | Get-VMQuestion | Set-VMQuestion -DefaultOption -confirm:$false;

do

{

  Start-Sleep -Seconds 5;

  $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

}while($toolsStatus -ne "toolsOK");

View solution in original post

8 Replies
schepp
Leadership
Leadership

Hi welcome to the communities,

I've moved your thread to the PowerCLI section of the forums. You'll get faster response here from the PowerCLI grandmasters Smiley Wink

The questions is how you want to check when your windows is ready. Maybe you could call it ready when you are able to successfully use the Invoke-VMScript cmdlet: Invoke-VMScript - vSphere PowerCLI Cmdlets Reference

Regards

Tim

0 Kudos
Tibo64
Contributor
Contributor

Thanks for your reponse.

Yes i know for invok-Vmscript because after check os is booting i want to invoke-vmscript Smiley Wink

I just want to know how i can find if the os is ready and when i can invoke vmscript

0 Kudos
naiksidd
Enthusiast
Enthusiast

hi,

1. After you poweron the vm put a initial wait for few seconds I generally prefer 20 secs to 30 secs.

2. write a do while loop to check tools status with additional 5 sec to 10 sec time out

3. wait till the tools status is ok.

4. run your invoke command after that.

I generally use this approach.

0 Kudos
naiksidd
Enthusiast
Enthusiast

may be this helps..

Start-vm -VM <Name> -runAsync

$vm = get-vm <name>

Start-Sleep -Seconds 20;

$vm  | Get-VMQuestion | Set-VMQuestion -DefaultOption -confirm:$false;

do

{

  Start-Sleep -Seconds 5;

  $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

}while($toolsStatus -ne "toolsOK");

Tibo64
Contributor
Contributor

Thanks i'm going to try.

Thanks

0 Kudos
MariusRoma
Expert
Expert

Let me re-open this topic.

The code looks usefull, but there is some problem, as the value of $toolsStatus is not updated.

So, the firts time the loop executes the value is "toolsNotRunning" but it is never updated, so the loop is infinite.

How can I make the script work as expected?

Regards

marius

0 Kudos
heskyttberg
Contributor
Contributor

Hi,

It's quite simple to fix, I had similar problem with other statuses and after thinking for a while and some testing I came up with this:

  do {

    Start-Sleep -Seconds 20;

    $vm = Get-VM $vm.name  # The new line that does the refresh.

    $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

  } while($toolsStatus -ne "toolsOK");

You have to look at it like the web client.

For example if you delete a vm it will still be present in the web client untill you press refresh.

so in powerCLI if you do $vm = Get-VM $vm.name, you refresh the $vm variable with current vm statuses and then you know the server should have started properly.

Regards

/Hasse

0 Kudos
stanbpd
Contributor
Contributor

This cannot be applied when installing modules where a reboot is required and windows is applying lot of settings after the reboot (applying computer settings), if you see this message the TOOLs are being reported as TOOLS OK, it works only for a standard reboot.

0 Kudos