Disks Part 4: Mount points
Posted by: Richard Siddaway
We have seen how to discover our physical and logical disks. In a quick digression I want to cover Mount Points. These allow us to mount the volume into an empty folder in the file system rather than having a new drive. They are useful when we have lots of volumes and need to conserve drive letters.
|
001
002 003 004 005 006 007 008 009 010 |
Get-WmiObject -Class Win32_MountPoint |
where {$_.Directory -like ‘Win32_Directory.Name="C:\\Data*"’} | foreach { $vol = $_.Volume Get-WmiObject -Class Win32_Volume | where {$_.__RELPATH -eq $vol} | Select @{Name="Folder"; Expression={$_.Caption}}, @{Name="Size (GB)"; Expression={"{0:F3}" -f $($_.Capacity / 1GB)}}, @{Name="Free (GB)"; Expression={"{0:F3}" -f $($_.FreeSpace / 1GB)}}, @{Name="%Free"; Expression={"{0:F2}" -f $(($_.FreeSpace/$_.Capacity)*100)}} } |
Our win32_MountPoint class only gives us directory and volume ID information. if we want more we have to link to the Win32_Volume class.
As we know where we have mounted our volumes we can filter on that folder – note the use of c:\\data – the \\ is a WMI syntax to escape the \.
For each mount point we find a volume with the correct ID. I’ve use __RELPATH in the filter as it takes the same syntax as the ID in win32_mountpoint so we don’t need to do any processing. Once we have our volume we can format the data in the way we have seen previously.




