Jump to content

Recommended Posts

Posted

Been trying to do this for years but now found this script which works, (think this is the right forum "Do you know how to do something? Do you want to let other people know? Post it in here.")

 

https://www.pdq.com/blog/mapped-drives/

# 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"
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...