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."
私は何を間違っていますか?