Thursday, July 03, 2014

Favorite Function for Checking Disk Space in PowerShell–includes Mountpoints and System Reserved Volumes

Found a superior function and added a parameter to check disk space compared to the old script I was using.

function df { Param([string[]]$ComputerName) Get-WMIObject Win32_Volume -filter "DriveType=3" -computer $ComputerName | Select SystemName,Caption,Label,@{Name="DiskSize(GB)";Expression={[decimal]("{0:N1}" -f($_.capacity/1gb))}},@{Name="freespace(GB)";Expression={[decimal]("{0:N1}" -f($_.freespace/1gb))}},@{Name="PercentFree(%)";Expression={"{0:P2}" -f(($_.freespace/1gb)/($_.capacity/1gb))}}}

Here’s an example of omitting system reserved volumes and passing multiple servernames in a text file:


No comments: