PowerShell snippet: “start a virtual machine and wait for a bit”

Over the last year there are a couple of PowerShell functions that have become a common set of many of my scripts.  One example is this “StartVMAndWait” function:

function StartVMAndWait($vmToStart){
start-vm $vmToStart
do {Start-Sleep -milliseconds 100} 
    until ((Get-VMIntegrationService $vmToStart | ?{$_.name -eq "Heartbeat"}).PrimaryStatusDescription -eq "OK")

This is a simple function that starts a virtual machine and then waits until the heartbeat integration component has returned a healthy status.  This is a good indicator that the guest operating system has completed booting – which makes this quite handy when you want to start a virtual machine and then interact with the guest operating system in some way.