Get-view is a faster way to retrieve the information about your VM in vCenter or Specific VM in the vCenter using the filter.I’ve started exploring the Get-view command in blogs posted by fellow CLI users.PSVMware Blogger,Did well analysis on CLI commands computation time,have look on it.Link available below in Recommendation section.

vmtools mandatory to retrieve few information like Disk Details and N/W details.

Source Code:
#Connect to vCenter
#Connect-VIServer -Server $vc -User $vcuser -Password $vcpass
$Report =@()

#Get the VM
$VMs = Get-view -ViewType VirtualMachine

# Add Filter to retrieve specific VM name
#Get-View -ViewType VirtualMachine -Filter @{“Name” = “do*”}

ForEach ($vm in $VMs)
$VMInfo = {} | Select VMName,OSName,VMVersion,IPAddressNIC1,VMToolVersion,VMToolsStatus,Num_CPU,~

~Mem_GB,TotalDisk,DiskCapacity,DiskFree,DiskUsed #,Powerstate
$VMInfo.VMName = $
#$VMInfo.Powerstate = $vm.summary.runtime.powerstate
$VMInfo.OSName = $vm.config.GuestFullName
$VMInfo.VMVersion = $vm.config.version
$VMInfo.IPAddressNIC1 = $vm.Guest.IPAddress
$VMInfo.VMToolVersion = $vm.Guest.ToolsVersion
$VMInfo.VMToolsStatus = $vm.Guest.ToolsStatus
$VMInfo.Num_CPU = $vm.config.Hardware.NumCPU
$VMInfo.Mem_GB = ($vm.config.Hardware.MemoryMB)/1024
$VMInfo.TotalDisk = $vm.Guest.Disk.Length
$VMInfo.DiskCapacity = [math]::Round($vm.Guest.Disk.Capacity/1GB)
$VMInfo.DiskFree = [math]::Round($vm.Guest.Disk.FreeSpace/1GB)
$VMInfo.DiskUsed = $VMInfo.DiskCapacity – $VMInfo.DiskFree

$Report += $VMInfo
#Information in GUI
$Report | Out-Gridview
#Export to CSV,Uncomment
#$Report | export-csv c:\scripts\test.csv

Recommend Link:


Thanks.Share it If you like