We can query network drives using PowerShell with the Get-WmiObject cmdlet. You can query the Win32_MappedLogicalDisk WMI class which represents network storage devices that are mapped as logical disks on the computer system.
Below is an example:
PS > $computer = "localhost" PS > Get-WmiObject Win32_MappedLogicalDisk -ComputerName $computer Name ProviderName ---- ------------ P: \\nas1\Private Z: \\nas2\Public
Note: You can query a remote computer with the $computer variable.
Many properties are available. Just use the Format-List cmdlet to list all the properties:
PS > Get-WmiObject Win32_MappedLogicalDisk -ComputerName $computer | fl *
Now you can easily display some interesting properties:
PS > Get-WmiObject Win32_MappedLogicalDisk -computerName $computer | select Name, ProviderName,FileSystem,@{Name="Total Size";Expression={ $_.size / 1GB}}, @{Name="Free Space";Expression={$_.freespace / 1GB}} | ft -AutoSize Name ProviderName FileSystem Total Size Free Space ---- ------------ ---------- ---------- ---------- P: \\nas1\Private NTFS 3681.69588470459 579.900218963623 Z: \\nas2\Public NTFS 3681.69588470459 579.900218963623
Thanks for reading! You can follow me on Twitter @PrigentNico