Hi all,
I'm trying to come up with a way to use PowerCLI to scan vCenter for templates that have had their disks deleted but not unregistered from vCenter. Templates aren't going to an inaccessible state like a VM would, so its been proving to be a bit of a challenge to detect this condition. Thus far when looking online, I've only seen cleaning up in the opposite direction, like LucD's Spring Cleaning script for deleting orphaned disks.
Does anybody have any suggestions for a method on detecting when a template is in vCenter, but the disks for it have been deleted?
Thanks,
Jason
Hi Jason,
the next PowerCLI command will show you the names of the templates that don't have a hard disk:
Get-Template | Where-Object {-not ($_ | Get-HardDisk)}
Hi RvdNieuwendijk,
I gave this a try and it looks like its not returning expected results. I switched it up and ran it as <Get-HardDisk -Template "templatename"> for testing on a template that I know has been deleted from the disk and it still returned all of the associated vmdk's. Browsing the datastore confirms that it has been deleted.
Thanks,
Jason
I suspect that this method will only work when the harddisk was removed with for example the Remove-Harddisk cmdlet.
When the VMDK file was deleted from the datastore, via for example the datastore browser, you will have to check if the VMDK is still there.
Something like this
Get-Template | Select Name,@{N="HD Present";E={
(Get-HardDisk -Template $_ | %{
Get-HardDisk -DatastorePath $_.Filename -Datastore $_.FileName.Split(']')[0].TrimStart('[')}) -ne $null}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
This method appears to be working correctly, just with the side effect that it is extremely slow to run. It took nearly 9 hours to collect the information from one lightly loaded datacenter (20 templates, 268 VMs).
Thanks,
Jason
That is indeed very slow :smileycry:
Which PowerCLI version are you using, there were some performance improvements in the last builds.
We could try to something similar but with the datastore provider, that should be a bit faster.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm running PowerCLI 5.5 connecting to a vCenter 5.0 server. For a comparison, I can run a slightly modified version of the "VMX Raiders Revisited" script (targeting templates instead) against the same datacenter in about 12 minutes.