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:
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
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.
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.