VMware Cloud Community
mishechkin
Contributor
Contributor

Wait-Tool - Object reference not set to an instance of an object.

Hello!
I use the next PowerShell script for starting VMs through Azure DevOps:

===

$Machines = ('VM1', 'VM2', 'VM3')

Get-VM -Name $Machines |

ForEach-Object {

    if ($_.PowerState -eq "PoweredOff") {
        Write-Host "Starting vm '$($_.Name)'."
        Start-VM -VM $_ -RunAsync
    }
} |
Wait-Task |
ForEach-Object {
    Write-Host "Waiting vm '$($_.Name)' tools to start."
    Wait-Tools -VM $_ -TimeoutSeconds 600
}
==
It work fine on all VMs except one VM, where I get the next error periodically:
mishechkin_0-1627183369538.png

After rerun of the deployment stage for this machine usually all work as expected. On all other VMs all works without this error and deployment looks good always. I tried to increase timeout, but it has no effect.

Could somebody help me ?

Thank you.

 
Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Which PowerShell and PowerCLI versions are you using?
Did you check if the Task created by Start-VM are Server-Side tasks or Client-Size tasks?
You can check the type/content of the returned object.

You seem to indicate the exception does not happen when you redeploy the VM that causes the issue.
Does that mean the next time you try to run Start-VM against that specific VM, the exception always occurs?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mishechkin
Contributor
Contributor

This task is executed on server (on AzDo Self-hosted agent)

PowerShell version on agent: 5.1 (Classic Windows PowerShell, not PowerShell Core), on all VMs: 5.0

mishechkin_0-1627271153355.png

This error is occur only on one VM, on others all works fine (all VMs have the same configuration)

>You seem to indicate the exception does not happen when you redeploy the VM that causes the issue.
>Does that mean the next time you try to run Start-VM against that specific VM, the exception always occurs?

Yeah, if I restart stage for failed machine right after error - all works fine, but I'll for sure face with this error in the next planned deployment (usually  on the next day).

Reply
0 Kudos
LucD
Leadership
Leadership

PowerCLI 5.5 was released in 2014, any reason why you are using such an old version?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mishechkin
Contributor
Contributor

Hello!

Sorry for delay.

I've used the new Azure DevOps self-hosted agent with modern VMVare PowerCLI, and I've got the another error for this VM (see the screenshot).

mishechkin_0-1629725910576.png

 

mishechkin_1-1629725969012.png

This error occurs when VM is not fully starter yet. It has VMWare tools installed:

mishechkin_2-1629726179871.png

As usual after restarting the Azure DevOps deployment all has been successful. But I think, I'll get this error in the next deployment.

Any ideas ?

Reply
0 Kudos
LucD
Leadership
Leadership

You can check with $vm.ExtensionData.Guest.GuestOperationsReady if the VMware Tools are ready.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mishechkin
Contributor
Contributor

Yeah, It works for me!

Thank you!

So, it look like Wait-Tools  doesn't work correctly, right ?

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership

The Wait-Tools cmdlet does work correctly, it just waits for the VMware Tools to be running.

To interact with the VMware Tools you have to make sure that VMware Tools are ready for "operations".
There is a small-time window between the VMware Tools running and being ready for operations.

So both options work, they just are used for different purposes.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mishechkin
Contributor
Contributor

And what's the right purpose for using Wait-tools ?
Early I used this cmdlet for detection of Guest OS is ready, but it sometimes raised the errors as above

Reply
0 Kudos
LucD
Leadership
Leadership

One reason to use Wait-Tools could be to verify that the values under the Guest property are up-to-date.
For interaction with the Guest OS, like Invoke-VMScript, I use the GuestOperationsReady flag.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos