- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get mapped drives using PowerShell?
There are few methods to get the mapped network drive using PowerShell.
CMD command method.
You can use the cmd command net use in PowerShell to get the mapped drives.
net use
Output
PS C:\WINDOWS\system32> net use New connections will be remembered. Status Local Remote Network ------------------------------------------------------------------------------- OK K: \localhost\shared folder Microsoft Windows Network OK L: \localhost\Shared Microsoft Windows Network The command completed successfully.
To get the mapped drives on the remote computer,
Invoke-Command -ComputerName RemoteComputer -ScriptBlock{Net use}
Or
Invoke-Command -ComputerName RemoteComputer -ScriptBlock{Invoke-Expression -Command "Net use"}
PowerShell WMI and CimInstance method.
You can also use the PowerShell WMI method with classname Win32_MappedLogicalDisk to get the mapped network drive on the local computer.
Get-WmiObject -ClassName Win32_MappedLogicalDisk | Select PSComputerName, Name,ProviderName PSComputerName Name ProviderName -------------- ---- ------------ DESKTOP-9435KM9 K: \localhost\shared folder DESKTOP-9435KM9 L: \localhost\Shared
To get the same on the remote computer.
Get-WmiObject -ClassName Win32_MappedLogicalDisk –ComputerName RemoteComputer | Select PSComputerName, Name,ProviderName
Using the CIM method.
Get-CimInstance -ClassName Win32_MappedLogicalDisk | Select SystemName, DeviceID, ProviderName
On the remote system.
Get-CimInstance -ClassName Win32_MappedLogicalDisk –ComputerName RemoteSystem | Select SystemName, DeviceID, ProviderName
Get-PSDrive method.
On the local computer, you can run Get-PSDrive PowerShell cmdlet but it will get all the available drives. To get the network drives we need to filter the output as given below.
Get-PSDrive | where{$_.DisplayRoot -match "\"}
Output
Name Used (GB) Free (GB) Provider Root ---- --------- --------- -------- ---- K 318.16 47.24 FileSystem \localhost\shared folder M 286.07 79.36 FileSystem \localhost\Shared Folder
To get mapped drives on the remote computer.
Invoke-Command –ComputerName RemoteComputer -ScriptBlock{Get-PSDrive | where{$_.DisplayRoot -match "\"}}
- Related Articles
- How to remove the mapped network drive using PowerShell?
- How to Get Windows features using PowerShell?
- How to get pagefile settings using PowerShell?
- Get all drives in C#
- How to get all the Get-Process properties using PowerShell?
- How to get the disk information using PowerShell?
- How to get environment variable value using PowerShell?
- How to get installed windows update using PowerShell?
- How to get IP address settings using PowerShell?
- How to get DNS IP Settings using PowerShell?
- How to get the folder size using PowerShell?
- How to get the disk performance using PowerShell?
- How to get the file extension using PowerShell?
- How to get the readonly files using Get-ChildItem in PowerShell?
- How to get windows firewall profile settings using PowerShell?

Advertisements