Skip to content

Instantly share code, notes, and snippets.

@PatrickTerlisten
Last active December 5, 2015 08:23
Show Gist options
  • Save PatrickTerlisten/0d240ad0c936270acfe8 to your computer and use it in GitHub Desktop.
Save PatrickTerlisten/0d240ad0c936270acfe8 to your computer and use it in GitHub Desktop.
This script outputs a list of all VMs that suffer from memory ballooning
#requires -Version 1
#requires -PSSnapin VMware.VimAutomation.Core
function Get-MemoryBallooningStats {
<#
.SYNOPSIS
No parameters needed. Just execute the script.
.DESCRIPTION
This script outputs a list of all VMs that suffer from memory ballooning.
.EXAMPLE
Get-MemoryBallooningStats
Get a list of all VMs that have ballooned memory.
.NOTES
Author: Patrick Terlisten, [email protected], Twitter @PTerlisten
This script is provided "AS IS" with no warranty expressed or implied. Run at your own risk.
This work is licensed under a Creative Commons Attribution NonCommercial ShareAlike 4.0
International License (https://creativecommons.org/licenses/by-nc-sa/4.0/).
.LINK
http://www.vcloudnine.de
#>
# Create an empty hash table
$Output = @()
# List of all VMs that suffer from memory ballooning
$VirtualMachines = (Get-View -ViewType VirtualMachine | Where-Object -FilterScript {$_.Summary.QuickStats.BalloonedMemory -ne '0' })
try
{
# ForEach Loop to fill the hash table
ForEach ($VM in $VirtualMachines) {
$OutputData = '' | Select-Object -Property VM, BalloonedMemory, MemLimit, MB
$OutputData.VMName = $VM.Name
$OutputData.BalloonedMemory = $VM.Summary.QuickStats.BalloonedMemory
$OutputData.MB = $VM.Summary.Config.MemorySizeMB
$OutputData.MemLimit = $VM.Config.MemoryAllocation.Limit
$Output += $OutputData
}
}
catch
{
"Error was $_"
$line = $_.InvocationInfo.ScriptLineNumber
"Error was in Line $line"
}
finally
{
# Output the filled hash table
If ($OutputData.Length -eq 0) {Write-Host -Object 'No VMs with memory ballooning detected!'}
else {$OutputData}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment