When I run the following script on my computer it runs with no problem. When I try and run on computers in a domain, it gets the PC name and Username but fail to return a value from the registry key. Any help on how to get it to pull the remote registry value would be great! I have enabled remote registry access on the computers in question.
Thank you!!
$computername = Get-Content -path ".\pclist2.txt" if (test-connection -computername $computername -quiet) { #Get PC name foreach ($pc in $computername) { #Who Is logged on $loggedon =@(Get-WmiObject -ComputerName $pc -Namespace root\cimv2 -Class Win32_ComputerSystem)[0].UserName; #Citrix Info from Registry $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('CurrentUser', $pc.computer) $regkey = $reg.OpenSubkey("SOFTWARE\\Citrix\\PNAgent") $LMPS = $regkey.GetValue("User Model 000") } } #Write Reg_Binary to String $String = [string]::Join($null, ($LMPS | % { [char][int]$_; })) #Isolate Username in String $Username = $String.Substring(29,8) #Write to .csv file Add-Content "c:\PS\Audit.csv" "$pc,$loggedon,$UserName"