我試圖從使用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