Skip to content

January 30, 2012

Get Guest VM Drive Sizes

by Scott Newman

Quick post on how to get the drive sizes and free space on said drives on VMWare Virtual Machines.  Props to this forum post.  I ran this on our esx’s and was able to identify over 2 terabytes of unused space.  Very handy.

cls

$user = 'UserName'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user, (get-content "c:\credentialFile.txt" | convertto-securestring )
#Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue
$visrv = Connect-VIServer -Server Server -Credential $cred

$dataCenter = Get-Datacenter -Name Location 

if(Test-Path('c:\ServerList.csv'))
{
	Remove-Item -Path c:\ServerList.csv -force
}

Get-VM -Location $dataCenter | %{ $vmName = $_.Name;
	$_.Guest.Disks | where{($_.FreeSpace/1GB) -gt 50} | Select `
			@{Name = "VirtualMachine"; E={$vmName}}, `
			@{Name = "Path"; E={$_.Path}}, `
			@{Name = "Capacity(GB)";E={[System.Math]::Round($_.Capacity/1GB, 1)}}, `
			@{Name = "FreeSpace(GB)";E={[System.Math]::Round($_.FreeSpace/1GB, 1)}}  
} | Export-Csv -Path 'c:\ServerList.csv'

Disconnect-VIServer -Server $visrv -Force
Read more from Powershell, VMWare

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

%d bloggers like this: