我试图从使用powershell的服务器获取远程注册表值。函数在Powershell中执行wmi查询时失败
我发现一些代码,在网上为我工作:
$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."
什么我做错了吗?
当您调用该函数时,请去掉parens和逗号。 – EBGreen 2013-03-01 15:59:35
我觉得很愚蠢......谢谢 – Jeff 2013-03-01 16:30:27