How To Display Mount Points and Drives Using PowerShell


To continue on with more useful PowerShell we cover getting details on drives including drives that are using mount points.

The Code

For the most part we will be making a call to WMI using win32_volumes class and using auto format to output to a table. In the output we want to display Disk free space, total space, disk percentage as well as name and  drive letter. The name output includes the full path to the mount point.


# Name getmntptdtls.ps1
# This will output specific details for mountpoints

$TotalGB = @{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}

function get-mountpoints {
$volumes = Get-WmiObject win32_volume -Filter "DriveType='3'"
$volumes | Select Name, Label, DriveLetter, FileSystem, $TotalGB, $FreeGB, $FreePerc | Format-Table -AutoSize



So what does it look like?



Another task handled by PowerShell, happy coding.

Leave a Reply

Your email address will not be published. Required fields are marked *