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.

Use Get-PSDrive to Get Mapped Drives

Use the PowerShell Get-PSDrive cmdlet to get all drives in the session.

Get-PSDrive

In the above PowerShell script, the command list drives in the current session.

The output of the above script shows the hard drives (C:, D:) and the other drives exposed by the Windows PowerShell provider ( Alias:, Cert:, Env:, Variable, HKCU:).

List Drives using PowerShell
List Drives using PowerShell

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:\> 

Use the net use Command to Get Mapped Network Drives

You can use the net use cmd in PowerShell to get all available mapped drives in the 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:\>  

In the above PowerShell script, the net use command lists mapped drives on the local system.

Cool Tip: How to get memory usage in PowerShell!

Using WMI to Get Mapped Network Drives

You can use WMI to get a list of mapped network drives on the computer. To use the WMI method, follow the below steps:

  1. Open a PowerShell terminal as an administrator
  2. Import the CIM cmdlets: Import-Module CIM

Let’s check with the help of the below examples to get a list of all mapped network drives on the local computer and remote computer.

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:\>                                                                                                                           

In the above PowerShell script, the Get-WmiObject cmdlet gets the list of all mapped network drives.

Get mapped drive on the remote computer using WMI

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

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

In the above PowerShell script, the Get-WmiObject gets mapped network drives on the remote computer specified by the ComputerName parameter.

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

Using the CIM Method to Get a Mapped Network Drive

Use the CIM method to get available mapped drive on the local computer

You can use the Get-CimInstance cmdlet in PowerShell which uses Win32_MappedLogicalDisk to list all mapped network drives on the local computer and show the mapped drives.

The following PowerShell script returns the list and shows 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, the Get-CimInstance command uses the Win32_MappedLogicalDisk class and gets a 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 the ShellGeek home page.