powershell - 在 powershell 中使用备用凭据读取远程注册表项

标签 powershell registry credentials

我正在使用以下函数来读取 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-CommandGet-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/

相关文章:

powershell - 统一文件集

python - 在 python 中读取文本文件(Powershell 脚本的输出)会产生意外结果?

c++ - C++中的BIOS信息

Android->Settings->Security->StorageType get Value inside app

regex - PowerShell多字符串替换效率

string - 格式化字符串以在24小时内添加前导零

c# - 在注册表中存储和加密 SMTP 凭据

windows-7 - 执行shell后立即运行一个进程 windows 7

java - 如何定义 GOOGLE_APPLICATION_CREDENTIALS?

git - aws codecommit 无法推送