VMware Cloud Community
Tibo64
Contributor
Contributor
Jump to solution

Powercli script start vm and check boot

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
Jump to solution

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
Jump to solution

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
Jump to solution

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
Jump to solution

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
Jump to solution

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
Jump to solution

Thanks i'm going to try.

Thanks

0 Kudos
MariusRoma
Expert
Expert
Jump to solution

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
Jump to solution

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
Jump to solution

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