Get Cloud Director VM Inventory with Storage Info (KB#00097)

 Hello Guys,

Keep fighting with Corona and keep your spirit up. It will help 😊

I got this challenge in form of a request from my customer. He requested all VM's info including cpu, mem and disk size. Initially I thought what's a big deal in it but then when I actually started writing code, I had the feeling like "What the heck" LOL!

Guys who already dealt with it, might know my pain. I started browsing google and found that many people are asking same question and I found vmware community thread too was unanswered. After a extensive search and hard work, I could do it. Below is the code guys:


==========
Function Get-CIVMInventory {
$ppp = Read-host "enter the vm name"
$vms = Get-CIVM -Name $ppp
Foreach ($vm in $vms){
$ee = $vm.ExtensionData.GetVirtualHardwareSection().item | Where {$_.Description -like “Hard Disk”}
$ff = $ee.VirtualQuantity.value
foreach ($f in $ff){
Get-CIVM -Name $vm | Select @{N="Name";E={@($vm.Name)}}, CPUCount, MemoryGB, @{N="DiskSize(GB)";E={@($f/1024/1024/1024)}}
}
}
Get-CIVMInventory
}
=========

Above is for single VM, you might be having requests like you want to fetch for all VMs in your cloud director environment then please use below code:

========
$vms = Get-CIVM
$output = Foreach ($vm in $vms){
$ee = $vm.ExtensionData.GetVirtualHardwareSection().item | Where {$_.Description -like “Hard Disk”}
$ff = $ee.VirtualQuantity.value
foreach ($f in $ff){
Get-CIVM -Name $vm | Select @{N="Name";E={@($vm.Name)}}, CPUCount, MemoryGB, @{N="DiskSize(GB)";E={@($f/1024/1024/1024)}}
}
}
$output | Import-Csv C:\Temp\fra_vcd_vm_invent.csv
=========

It is tested and working for me. Give it a try and let me know if it doesn't work for you😊 I answered the VMware thread too.