Hi, this script gets a VM´s disks and lists total, free and free% space:
# Get VM disk space usage
Clear-Variable -name Output
$Output = @()
$cluster = Get-Cluster "clustername"
ForEach ($VM in $cluster | Get-VM | where-object {($_.powerstate -ne "PoweredOff")})
{
ForEach ($Drive in $VM.Extensiondata.Guest.Disk)
{
$Path = $Drive.DiskPath
#Calculations
$Freespace = [math]::Round($Drive.FreeSpace / 1MB)
$Capacity = [math]::Round($Drive.Capacity/ 1MB)
$SpaceOverview = "$Freespace" + "/" + "$capacity"
$PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)
$Output = $Output + "Vm: " + $VM.Name + "`n"
$Output = $Output + "Disk: " + $Path + "`n"
$OutPut = $Output + "Free(MB): " + $Freespace + "`n"
$Output = $Output + "Free(%): " + $PercentFree + "`n"
$Output = $Output + "Capacity: " + $Capacity + "`n"
write-host $VM.name $path $Capacity "Total " $Freespace "Free " $PercentFree "%Free "
}
}
Results look like this:
computername D:\ 40957 Total 37061 Free 90 %Free
computername C:\ 76448 Total 48177 Free 63 %Free
Maybe this works for you?