I am trying to get registry keys with the value OEMInformation from a list of computers but can't seem to get it to work. What am I missing?
$strMachineName = import-csv C:\temp\PCs.csv
foreach ($line in $strMachineName)
{
try {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $line.computer)
$regkey = $reg.OpenSubkey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion")
$serialkey = $regkey.GetValue("OEMInformation")
('"{0}","{1}"' -f $line.computer, $OEMInformation) | out-file C:\temp\stdout.csv -append -encoding ascii
} catch {
('"{0}","{1}"' -f $line.computer, $_) | out-file C:\temp\stderr.csv -append -encoding ascii
}
}
$strMachineName = import-csv C:\temp\PCs.csv
foreach ($line in $strMachineName)
{
try {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $line.computer)
$regkey = $reg.OpenSubkey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion")
$serialkey = $regkey.GetValue("OEMInformation")
('"{0}","{1}"' -f $line.computer, $OEMInformation) | out-file C:\temp\stdout.csv -append -encoding ascii
} catch {
('"{0}","{1}"' -f $line.computer, $_) | out-file C:\temp\stderr.csv -append -encoding ascii
}
}