How to see if a VM have a pending image

This is a spin-off from the prevues post, but in the reddit thread one other user was struggling to get information from Instant-Clone VMs if they did have a pending image.

This is something that is really nice for IT-Support to know, I have built this function in my Webb Application for our IT-Support staff.

Anyway, we do have a function for this already in my vOperator module. Once again keep in mind that I have not made any major error handling in it and that the module are in Beta stage. I’ll update it and make it production ready with a bunch of new features etc.

You can find the module at GitHub or PSGallery

You can find instruction how to install vOperator here

First we do need to connect to a connection server to collect some auth information, we will store this and re-use it during this code. You can connect to any connection server in your POD.

$hvConnect = Connect-hvSrv -hvFQDN $hvFQDN -Cred $Cred -Domain $Domain

Next up we need to collect some information about the pool so we can get some necessary information.

$PoolInfo = $hvConnect | Get-hvDesktopPool -FilterValue $PoolName

Now when we do have that we need to collect all of the VMs that are in that pool, we can easy do that if we execute this command.

$GetPoolVM = $hvConnect | Get-hvVM -FilterName "desktop_pool_id" -FilterValue $($PoolInfo.ReturnValue.Id)

Now we can check out the information that we have collected, write $GetPoolVM.ReturnValue and we should get something like this.

Screenshot 2024 02 04 At 23.07.38

As you can see we do get a lot of information here, I have just printed a picture over one VM but I do assume that you have multiple VMs in your pool so all of them will get collected.
As all of them get collected you might want to just get the one you’re searching for, you can do that with the following line.

$GetVM = $GetPoolVM.ReturnValue | Select-Object {$_.name -like "YOURVMNAME"}

And now just write $GetVM to see all information about that specific VM.
We can also expand properties like manage_machine_data to show even more information about the VM, you can do that with

$GetVM.manage_machine_data

But we are looking for if the image have any pending image, we can get that information from the operation_state parameter, if it’s stating PUSH_IMAGE then the VM have a pending image and are not on the latest snapshot. To get that information write the following line

$GetVM.manage_machine_data.operation_state

And we can also sort out and collect all images that have a pending image.

# Collect all VMs that have a pending image
$GetPending = $GetPoolVM.ReturnValue | Select-Object {$_.manage_machine_data.operation_state -like "PUSH_IMAGE"}

# Write all of them out
$GetPending

Time are outputted here as “linux time” to convert that to something you can read you can use this

# Convert time to something that you can read
$CreateTime = [datetimeoffset]::FromUnixTimeMilliseconds($GetVM.manage_machine_data.create_time).DateTime
$CreateTime

2 thoughts on “How to see if a VM have a pending image

  1. Your articles are very helpful to me. May I request more information?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.