Forum

You need to log in to create posts and topics.

Export a CSV report of all VMs and details on vCenter

This nifty little PowerCLI will provide you with a quick report of all the VMs within vCenter:

$ExportPath = "C:\temp\VM_report.csv"
$VmInfo = Get-VM
$VMS = ($VmInfo).Name
$VCenter = @()
foreach ($VM in $VMS)
{
    $HostServer = (($VmInfo | ? {$_.Name -eq $VM}).Host).Name
    $VMSysInfo = Get-VMGuest -VM $VM
    $MyObject = New-Object PSObject -Property @{
       VMName = $VM
       VMHostName = $VMSysInfo.HostName
       VMIP = $VMSysInfo.IPAddress
       VMInstalledOS = $VMSysInfo.OSFullName
       PowerState = ($VmInfo | ? {$_.Name -eq $VM}).PowerState
       NumberOfCPU = ($VmInfo | ? {$_.Name -eq $VM}).NumCpu
       MemoryGB = (($VmInfo | ? {$_.Name -eq $VM}).MemoryMB/1024)
       VMDataS = (Get-Datastore -VM $VM).Name
       HostServer = (($VmInfo | ? {$_.Name -eq $VM}).Host).Name
       HostCluster = (Get-Cluster -VMHost $HostServer).Name    
    }
       $VCenter += $MyObject
}
$VCenter | 
Select VMName,
       VMHostName,
       @{N='VMIPAddress';E={$_.VMIP -join '; '}},
       VMInstalledOS,
       PowerState,
       NumberOfCPU,
       MemoryGB,
       @{N='VMDataStore';E={$_.VMDataS -join '; '}},
       HostServer,
       HostCluster | 
Export-Csv $ExportPath -NoTypeInformation
  • Don't forget you always need to connect to the vCenter first with the "Connect-VIServer" command

COMMENTS