Lately a couple of our Cluster Shared Volumes have been hitting a high percentage of usage, to alleviate any issues, I wanted a simple way to find out which VMs had the largest disk usage on those volumes. I chose to query volumes that were over 70% usage and the top 5 storage hogging VMs from those.
Credit goes to this post as getting a proper output of the paths and percentage is a real pain with the Failover Clustering CMDLets.
function Get-LargestVMs {
function Get-LargeVMs ($Path) {
$Size = get-vm -vmmserver "IP" | Where-Object {$_.vmcpath -like "*$Path*"} | Select Name,TotalSize,Hostname | Sort-Object TotalSize -Descending | Select-Object -First 5 | Out-String
Write-Host $Size
}
$objs = @()
$csvs = Get-ClusterSharedVolume -Cluster "Cluster"
foreach ( $csv in $csvs )
{
$csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
foreach ( $csvinfo in $csvinfos )
{
$obj = New-Object PSObject -Property @{
Path = $csvinfo.FriendlyVolumeName
PercentFree = $csvinfo.Partition.PercentFree
}
$objs += $obj
}
}
$objs | foreach {
if ($_.PercentFree -ge "70") {
Write-Host "################################################"
Write-Host $_.Path
Write-Host "Current percent free is"$_.PercentFree
Write-Host "################################################"
Get-LargeVMs $_.Path
}
else {
}
}
}















