我使用以下函数来读取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
答案 0 :(得分:1)
如果您可以使用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