title: How to get mapped drives on remote users session
body: <p>I need to get real mapped drives on remote session, I read remote registry for Path and Name but the label (drive letter) are missing in \Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2</p>
  
  <p>If I read HKCU\Network I have only the persistent drive (GPP drive with status Replace are missing).</p>
  
  <p>how do I find the path, the name and the label ?</p>
  
  <pre><code>function get-Drives {
          param ( [ValidateNotNullOrEmpty()] $Computername, [ValidateNotNullOrEmpty()] $SID )
          try {
              $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('USERS', $computerName)
              $RegKey = $Reg.OpenSubKey("$SID\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2")
              $lecteurs = $RegKey.GetSubKeyNames()
              $lecteurs | ?{$_ -notlike '{*}'} | %{
                  $RegKey = $Reg.OpenSubKey("$SID\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2\\$_")
                  $_LabelFromReg = $regKey.GetValue('_LabelFromReg')
                  if ($_LabelFromReg) {
                      [pscustomobject]@{
                          Name = $_LabelFromReg
                          Label = ''
                          Path = $_ -replace('#','\')
                      }
                  }
              }
          } catch {
          }
      }
  </code></pre>