Reputation: 11
How can I get free space and other informations about drives which have no drive letter, the drives were mounted in a NTFS folder with the disk management console, local on a win 10 workstation ? I need a solution in powershell, can somebody give me a hint?
Upvotes: 1
Views: 538
Reputation: 13567
This is a really tricky one! The WMI namespace Win32_MountPoint
has the info we need to see which drives are mounted as a disk drive or a folder.
The bottom entry is an example of a drive mounted as a folder.
#Use Get-WmiObject Win32_MountPoint if the below fails
PS> Get-CimInstance Win32_MountPoint
Directory : Win32_Directory (Name = "H:\")
Volume : Win32_Volume (DeviceID = "\\?\Volume{38569fb2-42e2-4359-8b42-1807...)
PSComputerName :
CimClass : root/cimv2:Win32_MountPoint
CimInstanceProperties : {Directory, Volume}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
Directory : Win32_Directory (Name = "C:\thumb")
Volume : Win32_Volume (DeviceID = "\\?\Volume{e5d29a99-c6c2-11eb-b472-4ccc...)
PSComputerName :
CimClass : root/cimv2:Win32_MountPoint
CimInstanceProperties : {Directory, Volume}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
With this info in mind...we can pass the DeviceID info over to another command to find out how much disk space there is.
get-volume | ? Path -eq $mount.Volume.DeviceID
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- ------------ -------------- --------- ------------ ----------------- ------------- ----
FAT32 Removable Warning Full Repair Needed 3.44 GB 3.74 GB
Now, let's make this into a function where you pass in the mount path and we return the info on the actual disk.
Function Get-MountedFolderInfo{
param($MountPath)
$mount = gcim Win32_MountPoint | where directory -like "*$MountPath*"
if ($null -eq $mount){
return "no mounted file found at $MountPath"
}
$volumeInfo = get-volume | Where-Object Path -eq $mount.Volume.DeviceID
if ($null -eq $VolumeInfo){
"Could not retrieve info for:"
return $mount
}
$volumeInfo
}
Get-MountedFolderInfo -MountPath C:\thumb
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- ------------ -------------- --------- ------------ ----------------- ------------- ----
FAT32 Removable Warning Full Repair Needed 3.44 GB 3.74 GB
Upvotes: 2