I still am lost. We determined you needed to use the SID of a logged on user. That is what you have done now. My first response noted that but your response confused me since you didn't seem to like the answer.
Glad you are set now. Good luck.
Get Mapped Drives using .net
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- MarvelManiac
- Posts: 63
- Last visit: Thu Sep 13, 2018 3:40 pm
Re: Get Mapped Drives using .net
I think you determined I needed the SID but I never stated that my friend
I just wanted to create a faster script than what I linked to using remote registry
Just hung up on creating a data set to import into my DGV
Thanks for the attempt. Sorry I didn't make it clear enough for you.
I just wanted to create a faster script than what I linked to using remote registry
Just hung up on creating a data set to import into my DGV
Thanks for the attempt. Sorry I didn't make it clear enough for you.
- MarvelManiac
- Posts: 63
- Last visit: Thu Sep 13, 2018 3:40 pm
Re: Get Mapped Drives using .net
This is my completed script
- $script:computer = 'Server1'
- $script:user = Invoke-Command -ComputerName $computer -ScriptBlock {
- (Get-ChildItem C:\users | Where { $_.Name -ne $env:USERNAME }).name | Select-Object -last 1
- }
- $objUser = New-Object System.Security.Principal.NTAccount("$user")
- $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
- $script:sid = $strSID.Value
- $regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::Users, $Computer)
- $ref = $regKey.OpenSubKey("$sid\Network")
- $keys = $ref.GetSubKeyNames()
- $results = foreach($key in $keys){
- $ref2 = $regKey.OpenSubKey("$sid\Network\$key")
- [pscustomobject]@{
- Drive = $key
- Path = $ref2.GetValue('RemotePath')
- }
- }
- MarvelManiac
- Posts: 63
- Last visit: Thu Sep 13, 2018 3:40 pm
Re: Get Mapped Drives using .net
Thanks, I'm extremely happy with my results. I really appreciate your time.