INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Lookup registry value of a key that contains the SID of logged on user

Lookup registry value of a key that contains the SID of logged on user

Lookup registry value of a key that contains the SID of logged on user

(OP)
It has been nearly 10 years since I have had to do any type of scripting and am having troubles putting two scripts together in a for each loop.
I need to find the SID of the currently logged on user and then use that SID in the path of the registry value I am looking for. I have been able to do this with the following code:

CODE

$List = get-content C:\Powershell\Scripts\wsns.txt $objUser = New-Object System.Security.Principal.NTAccount("us", "sxskiba") $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) $strSID.Value Get-regvalue -computername $List -hive "Users" -key "$strSID\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -value "AutoConfigURL" | Export-csv C:\Powershell\Scripts\output.csv -notypeinformation

However, this code has the domain and username explicitly defined. I need the domain and username to be found with powershell given a list of workstations. I have this script that will find the currently logged on domain\user

CODE

get-content C:\Powershell\Scripts\wsns.txt | ForEach-Object {gwmi -computer $_ -class win32_computerSystem} | fl Name, UserName | out-file C:\Powershell\Scripts\output.csv

How do I put these two together in a for each loop to work through a list of workstations? Desired output would be a csv with the computer name, logged on username, and value of the AutoConfigURL key.

RE: Lookup registry value of a key that contains the SID of logged on user

Untested but give this a try.

CODE

get-content C:\Powershell\Scripts\wsns.txt |
ForEach-Object {gwmi -computer $_ -class win32_computerSystem} | fl Name, UserName |
% {
$List = get-content C:\Powershell\Scripts\wsns.txt
$objUser = New-Object System.Security.Principal.NTAccount($_.Name, $_.UserName)
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
Get-regvalue -computername $List -hive "Users" -key "$strSID\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -value "AutoConfigURL" | Export-csv C:\Powershell\Scripts\output.csv -notypeinformation
}

I hope that helps.

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.

RE: Lookup registry value of a key that contains the SID of logged on user

I can see one minor issue there - the export-csv is inside the for-each loop. You can only export-csv once. You can't append (a big complaint from PowerShell guys like me), so export-csv is gonna complain the file exists. If you overwrite the file, then it's only ever going to have the last iteration of data.

What you'd probably need to do is just append the data to a text file. You could then read it all in at the end and export to csv in one move. YMMV.

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close