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

read a remote registry key with alternate credentials in powershell

我正在使用以下函数在 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

这对我有用,我想查找系统所需的挂起重启:

$HKLM = [UInt32] "0x80000002"
$WMI_Reg = Get-Wmiobject -list "StdRegProv" -namespace root\default -Computername $computer -Credential $Cred
$RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\") 
$CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"