$AllVolume = Get-WmiObject Win32_Volume |select name ,DriveLetter,FreeSpace,Capacity
foreach($vol in $AllVolume ){
if ([string]::IsNullOrEmpty( $vol.DriveLetter)){ }
else{
$l = "{0:N2}" -f ($vol.FreeSpace /$vol.Capacity *100)
"{0}的磁盘空闲率为 {1} %" -f $vol.DriveLetter , $l
}
}