I'm new to powershell. I'm trying to get some registry info from a list of networked machines and from my research it looks like powershell is the way to go.
My issue is, when I hardcode the computer name it works. When I use a variable from importing a list from csv file, I get errors.
I have used numerous ways of writing the code and I always get the same error.
With the OpenRemoteBaseKey, I have used the variables $line and $machinename. Neither work.
The error - Exception calling OpenRemoteBaseKey with 2 arguments: The network path was not found.
If I replace $line with the actual computer name it works. When I output the variable to powershell it gives me the computer name so I'm not sure what the issue is.
Any help would be appreciated!
$MachineName = import-csv somepath\computer_name.csv
foreach($line in $machinename){
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $line)
$key = $reg.OpenSubKey('SOFTWARE\rmp')
$keyvalue = $key.GetValue("build type")
$line | out-file somepath\computerinfo.txt -append
}
$key.Close()
$reg.Close()