Here is the script to collect vmware virtual machines details and export to an excel (.csv) using vSphere PowerCLI commands. This will help Vmware administrator to take a report of Memory, CPU usage, Data store, HDD space allocation, Host server, Guest OS etc.. here we are using command “get-vm” and “Select-Object” to filter the properties of virtual machine
How to connect to Vcenter/ESXi Server
First you have to connect to the vmware server. It can be a ESXi server or a Vcenter
PowerCLI C:\> Connect-VIServer
It will prompt the server address.
cmdlet Connect-VIServer at command pipeline position 1 Supply values for the following parameters: Server:
Enter the IP address and hit ENTER
Then a new window will prompt from authentication credentials of the VMware server
Export VM list
Once you connected to the server, you can run VM commands to get the output, Following script will give you a list of guest servers with Name of the virtual machine, Number of CPU, Memory, Disk Space
Get-VM | Select-Object Name, NumCPU, MemoryMB, ProvisionedSpaceGB | Export-Csv "Report.csv"
Find the list of List of VM Property Names here. you can use this names after “select-object” . separated by comma
Use “out-gridview” instead of “Export-Csv“ to get a sample output. See the figure