我正在尝试使用 powershell 从服务器获取远程注册表值。
我在网上找到了一些对我有用的代码:
$strComputer = "remoteComputerName"
$reg = [mcrosoft.win32.registryKey]::openRemoteBaseKey('LocalMachine',$strComputer)
$regKey = $reg.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion")
$regKey.getValue("ProgramFilesDir")
但是当我尝试把它放在一个函数中时:
$strComputer = "remoteComputerName"
function getRegValue {
param($computerName, $strPath, $strKey)
$reg = [mcrosoft.win32.registryKey]::openRemoteBaseKey('LocalMachine',$computerName) #Errors out here
$regKey = $reg.OpenSubKey($strPath)
$regKey.getValue($strKey)
}
$a = "Software\\Microsoft\\Windows\\CurrentVersion"
$b = "ProgramFilesDir"
getRegValue($strComputer, $a, $b)
错误:
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The endpoint format is invalid."
我究竟做错了什么?