Getting VM Information using Get-view

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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s