我正在使用以下函数来读取 powershell 中的远程注册表项,但我现在需要传递备用凭据。我该怎么做?
我已经使用 get-credential 命令将凭据存储在 $cred 中。
Param($computer)
$HKEY_Local_Machine = 2147483650
$reg = [WMIClass]"\\$computer\ROOT\DEFAULT:StdRegProv"
$Key = "SOFTWARE\Wow6432Node\Symantec\Symantec Endpoint Protection\CurrentVersion\SharedDefs"
$ValueName = "DEFWATCH_10"
$results = $reg.GetStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName)
write $results.sValue
最佳答案
如果您可以使用 psremoting,我建议将 Invoke-Command
与 Get-Item
结合使用作为替代方案。
$value = Invoke-Command -Scriptblock {Get-Item "HKLM:\SOFTWARE\Wow6432Node\Symantec\Symantec Endpoint Protection\CurrentVersion\SharedDefs\DEFWATCH_10"} -Credentials $cred -Computername $computer
如果您必须使用 WMI,您可以尝试如下操作:
$wmi = Get-Wmiobject -list "StdRegProv" -namespace root\default -Computername $computer -Credential $cred
$value = $wmi.GetStringValue($HKEY_Local_Machine,$key,$valuename).svalue
关于powershell - 在 powershell 中使用备用凭据读取远程注册表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30088795/