Skip to content

How to use PowerShell to get mapped drives

Jordan Hammond fun headshot
Jordan Hammond|Updated May 4, 2026
How to use PowerShell to get Mapped Drives
How to use PowerShell to get Mapped Drives

TL;DR: Use PowerShell to get mapped drives by querying Registry::HKEY_USERS\*\Network\* with Get-ItemProperty. The script returns mapped drive details for logged-on users, including username, drive letter, remote path, connection username, and SID, then formats the results with a PSCustomObject for cleaner reporting.

Mapped drives are easy to miss when you’re trying to understand how users connect to shared resources across your environment. PowerShell gives you a cleaner way to surface those mappings, especially when you want the results in a format that’s easier to scan, report on, or use in PDQ.

That's where the PowerShell Scanner comes in. Because scanner scripts return structured objects, you can turn mapped drive data into searchable inventory columns in PDQ instead of manually checking each device. We even have a few scripts available right out of the gate to help you see how to write your own and get the best results.

PowerShell podcast logo

PowerShell power user?

Check out The PowerShell Podcast: a weekly exploration of tips and tricks to help you step up your PowerShell game.

How do you get mapped drives with PowerShell?

To get mapped drives with PowerShell, query Registry::HKEY_USERS\*\Network\* with Get-ItemProperty. This returns mapped network drive data for user profiles currently loaded in HKEY_USERS, which most often means currently logged-on users. It won’t reliably capture mappings for profiles whose registry hives aren’t loaded.

$Drives = Get-ItemProperty "Registry::HKEY_USERS\*\Network\*"

How do you format mapped drive results in PowerShell?

The basic registry query returns mapped drive data, but the raw output is not ideal for reporting. You can use Select-Object for a quick view of the drive letter and remote path.

$Drives = Get-ItemProperty "Registry::HKEY_USERS\*\Network\*" | Select-Object pschildname, remotepath

This works if you only need the drive letter and remote path, but the output is limited and the property names are not very admin-friendly. To make the results easier to read and report on, the script stores the values in a PSCustomObject and adds clearer fields.

First, the script extracts the SID from the parent registry path. That SID is used to return both the SID and the corresponding username.

$SID = ($Drive.PSParentPath -split '\\')[2]

Now that we have that we just need to put all that we have captured into the PSCustomObject.

[PSCustomObject]@{ # Use .NET to look up the username from the SID Username = ([System.Security.Principal.SecurityIdentifier]"$SID").Translate([System.Security.Principal.NTAccount]) DriveLetter = $Drive.PSChildName RemotePath = $Drive.RemotePath # The username specified when you use "Connect using different credentials". # For some reason, this is frequently "0" when you don't use this option. I remove the "0" to keep the results consistent. ConnectWithUsername = $Drive.UserName -replace '^0$', $null SID = $SID }

That should be all you need, but let’s show what it looks like when it is all put together.

Full PowerShell script to get mapped drives

The full script gets mapped drives from HKEY_USERS, extracts the user SID, translates the SID to a username, and returns the results as a clean PowerShell object.

# This is required for Verbose to work correctly. # If you don't want the Verbose message, remove "-Verbose" from the Parameters field. [CmdletBinding()] param () # On most OSes, HKEY_USERS only contains users that are logged on. # There are ways to load the other profiles, but it can be problematic. $Drives = Get-ItemProperty "Registry::HKEY_USERS\*\Network\*" # See if any drives were found if ( $Drives ) { ForEach ( $Drive in $Drives ) { # PSParentPath looks like this: Microsoft.PowerShell.Core\Registry::HKEY_USERS\S-1-5-21-##########-##########-##########-####\Network $SID = ($Drive.PSParentPath -split '\\')[2] [PSCustomObject]@{ # Use .NET to look up the username from the SID Username = ([System.Security.Principal.SecurityIdentifier]"$SID").Translate([System.Security.Principal.NTAccount]) DriveLetter = $Drive.PSChildName RemotePath = $Drive.RemotePath # The username specified when you use "Connect using different credentials". # For some reason, this is frequently "0" when you don't use this option. I remove the "0" to keep the results consistent. ConnectWithUsername = $Drive.UserName -replace '^0$', $null SID = $SID } } } else { Write-Verbose "No mapped drives were found" }

Ready to get the most out of the PowerShell Scanner? Learn more about PowerShell Scanner best practices, and sign up for a free trial of PDQ to get started!

Related articles