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
Leave a comment