Home » PowerShell » How to get mapped network drives using PowerShell

How to get mapped network drives using PowerShell

More often system administrator has to get mapped network drives to get information about available network drives or remove mapped network drives if not required.

Using PowerShell Get-PSDrive or net use in cmd, you can easily get mapped drives. There are other ways like PowerShell WMI or CimInstance method to get mapped drives in Windows System.

In this article, I will explain how to use PowerShell Get-PSDrive and net use in cmd to get mapped network drives.

Using Get-PSDrive to get mapped drives

Using PowerShell Get-PSDrive cmdlet, get all available drives.

PS C:\> Get-PSDrive                                                                                                     
Name           Used (GB)     Free (GB) Provider      Root                              CurrentLocation
----           ---------     --------- --------      ----                              ---------------
Alias                                  Alias
C                 178.90         10.99 FileSystem    C:\
Cert                                   Certificate   \
D                 252.37         30.57 FileSystem    D:\
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
K                 252.37         30.57 FileSystem    \\Corp-in-18\Software
Variable                               Variable
WSMan                                  WSMan

To get a specific network drive with the letter k, use the Where condition to check the name equal to the drive letter as given below

PS C:\> Get-PSDrive | Where {$_.Name -eq "K"}                                                                           
Name           Used (GB)     Free (GB) Provider      Root                           CurrentLocation
----           ---------     --------- --------      ----                           ---------------
K                 252.37         30.57 FileSystem    \\corp-in-18\Software


PS C:\> 

Get mapped network drives using net use

Use net use cmd in PowerShell, get all available mapped drives in Windows System

PS C:\> net use                                                                                                         New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           K:        \\corp-in-18\Software Microsoft Windows Network
The command completed successfully.

PS C:\>  

The above PowerShell script, lists mapped drives on the local system.

Cool Tip: How to get memory usage in PowerShell!

Using WMI to get mapped network drives

Use WMI to get available mapped drive on the local computer

PowerShell WMI method, Win32_MappedLogicalDisk class is used to get mapped network drive on local computer

PS C:\> Get-WmiObject -ClassName Win32_MappedLogicalDisk | Select PSComputerName, Name,ProviderName
>>                                                                                                                      
PSComputerName Name ProviderName
-------------- ---- ------------
corp-in-20      K:   \\corp-in-18\Software


PS C:\>                                                                                                                           

Get mapped drive on the remote computer using WMI

Using WMI method, Win32_MappedLogicalDisk class is used to get mapped network drive on the remote computer.

Get-WmiObject -ClassName Win32_MappedLogicalDisk –ComputerName corp-in-200| Select PSComputerName, Name,ProviderName

In the above command, it gets mapped network drives on the remote computer specified by the ComputerName parameter.

Cool Tip: How to use a multiline command in PowerShell!

Using CIM Method to get mapped network drive

Use CIM method to get available mapped drive on local computer

Refer to the below command to view mapped drives on the local system

PS C:\> Get-CimInstance -ClassName Win32_MappedLogicalDisk | Select SystemName, DeviceID, ProviderName                  
SystemName     DeviceID ProviderName
----------     -------- ------------
corp-in-20  K:       \\corp-in-18\Software


PS C:\>           

Cool Tip: How to get the driver’s version using PowerShell!

Using the CIM method to get mapped drive on a remote computer

To get mapped network drives on a remote computer using the CIM method, use the below command

Get-CimInstance -ClassName Win32_MappedLogicalDisk –ComputerName RemoteComputer | Select SystemName, DeviceID, ProviderName

In the above command, it gets mapped network drive on the remote computer specified by the ComputerName parameter.

Cool Tip: Get Printer IP address, port, and model information using PowerShell!

Conclusion

I hope you like the above article on how to get mapped network drive using PowerShell.

We have seen different ways like Get-PSDrive, net use, WMI method, and CIM method to list mapped drives and mapped network drives on the local computer and remote systems.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment