远程注册表PC列表

时间:2014-05-29 16:46:08

标签: powershell registry

我试图从计算机列表中获取OEMInformation密钥的远程注册表值,但似乎无法使其工作。我收到这个错误:

Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found"

我缺少什么?

$strMachineName = import-csv C:\temp\PCs.txt
foreach ($line in $strMachineName)
{
    try {
        $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Computer)
$regkey=$reg.OpenSubkey('SOFTWARE\Microsoft\Windows\CurrentVersion\OemInformation')
 'MODEL:{0}  Manufactured by:"{1}"' -f $regkey.GetValue('Model'),$regkey.GetValue('Manufacturer')

}   

Catch{
           Write-Host "$_"  -fore red
     }
 }
$results|Export-Csv C:\temp\PCs-Results.csv -NoType

1 个答案:

答案 0 :(得分:0)

您在以下行中引用的$Computer - 变量不存在。

[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Computer)

你的txt文件的内容是否有标题?例如:

Computer
Machine1
Machine2

然后尝试

[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Line.Computer)

如果您的txt文件每行只包含一个计算机名称且没有标题,请将Import-CSV替换为Get-Content并尝试

[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Line)