2015-05-06 42 views
0

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

回答

0

如果你可以使用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 
+0

我用WMI解決方案,它的工作非常適合我。 – user2369812