Create a report of your Virtual Machine inventory in VMware vSphere with PowerCLI

Here’s a short Powershell script that outputs your virtual machine inventory to a csv-file.
Replace VCip with the ip of your vCenter server.
Replace VCuser and VCpass with, preferably, a read-only user with access to your vCenter environment.

Save the code to, for example, vm-report.ps1 and then execute it in PowerCLI.

script type="text/javascript">

connect-viserver -server VCip -user VCuser -password VCpass
Get-View -ViewType VirtualMachine | %{
New-Object PSObject -Property @{
Name = $_.Name
Host = (Get-View $_.Summary.Runtime.Host).Name
Datastore = [system.String]::Join(",",($_.Storage.PerDatastoreUsage | %{Get-View $_.Datastore} | %{$_.Name}))
Size = (Get-VM $_.Name | Select-Object -Property ProvisionedSpaceGB).ProvisionedSpaceGB #($_.Storage.PerDatastoreUsage | Measure-Object -Property Committed -Sum).Sum
CPU = (Get-VM $_.Name | Select-Object -Property numCPU).NumCpu
Memory = (Get-VM $_.Name | Select-Object -Property MemoryMB).MemoryMB
Network = (Get-NetworkAdapter $_.Name | Select-Object -Property NetworkName).NetworkName
} | Export-Csv "C:\VM-report.csv" -NoTypeInformation -UseCulture

It reports the following properties of all the VM’s:
Name of the VM
The portgroup/network(s) the VM is connected to
The disk(s) size of the VM
The memory configured for the VM
The amount of vCPUs configured for the VM
The datastore(s) the VM’s disks reside on
The host the VM is running on

If you open it in Excel, It’ll look something like this:





This entry was posted in PowerCLI, VMware and tagged , , , , , , . Bookmark the permalink.
  • Sajeesh_mac

    Thak you its working . I want to add IP address of the VM also in the out put. Could you please help ? 

  • Chaitanya

    worked like a charm dude.. thanks a ton!!