Using PowerCLI to Export Virtual Machine Inventory to CSV

In this post we will discuss the method to export a list of VMware Virtual Machines to a CSV file using PowerCLI.

Difficulty Level: Advanced


Introduction

It should already be common knowledge that this task can be manually done through the vCenter GUI. But, I am currently in the process setting up a "poor man's" backup solution which requires a CSV file of all VMs. Since I require the backup solution to be 100% automated, I needed a list of VMs to be updated automatically as business needs change.

We will be using the "Get-VM" cmdlet and piping it to the "Export-csv" cmdlet to get the information we need. To do anything with PowerShell in vSphere you will first need to install VMware vSphere PowerCLI.


Export VM Inventory to CSV via PowerCLI

Open PowerCLI and connect to your VMware vCenter server by typing:

Connect-VIServer vCenterServerName

Note: Replace "vCenterServerName" with your vCenter Server's name.

The simplest way to get a VM inventory with all inclusive information is to use the following command: 

Get-VM | Export-Csv -path "c:\vminventory.csv" -NoTypeInformation

This will compile a list of all VMs to a CSV file containing the following fields:
PowerState, Version, Description, Notes, Guest, NumCpu, MemoryMB, MemoryGB, HardDisks, NetworkAdapters, UsbDevices, CDDrives, FloppyDrives, Host, HostId, VMHostId, VMHost, VApp, FolderId, Folder, ResourcePoolId, ResourcePool, PersistentId, UsedSpaceGB, ProvisionedSpaceGB, DatastoreIdList, HARestartPriority, HAIsolationResponse, DrsAutomationLevel, VMSwapfilePolicy, VMResourceConfiguration, Name, CustomFields, ExtensionData, Id, Uid, Client

Let's say you only needed a handful of data for each VM. 

Get-VM | select Name, Description, PowerState, NumCpu, MemoryGB | Export-Csv -path “c:\vminventory.csv” -NoTypeInformation

In my case I only need the Name column and need the list sorted alphabetically:

Get-VM | select Name | sort Name | Export-Csv -path “c:\vminventory.csv” –NoTypeInformation

Once I complete setting up my "poor man's" VM backup solution I will update this post. Cheers! 

No comments

Back to Top