PowerCLI: Export VM Memory Limits to csv


I wanted to see how the memory limits are configured in my VI3 environment. You can do this via the VIC, but you can also do it via a PowerCLI script and export it to a csv file.

Copy the script and run it. The script will ask you to enter the vCenter server and a path to save the csv file (like c:\temp\memlimits.csv).

$vCenter = Read-Host "Enter vCenter Server"
$csvFile = Read-Host "Enter csv file"

Connect-VIServer $vCenter

Get-VM | sort name | % { $vm = $_ | Get-View ; $vm | select `
    @{ Name = "VM Name"; Expression ={ $vm.Name }},`
    @{ Name = "Memory in MB"; Expression ={ $vm.Config.Hardware.MemoryMB }},`
    @{ Name = "Memory Limits in MB"; Expression ={ $vm.Config.MemoryAllocation.Limit }}`
    } | Export-Csv -NoTypeInformation $csvFile

Invoke-Item $csvFile

Disconnect-VIServer -Confirm:$false

The output will look like this: