Looping through registry with alternate credential.
hello posh expert,
i have function show installed programs in particular server box.
function checkregkey{ param([string]$srv) $key = "software\microsoft\windows\currentversion\uninstall" $type = [microsoft.win32.registryhive]::localmachine $regkey = [microsoft.win32.registrykey]::openremotebasekey($type, $srv) $regkey = $regkey.opensubkey($key) foreach($sub in $regkey.getsubkeynames()) { if($regkey.opensubkey($sub).getvalue("displayname")) { $regkey.opensubkey($sub).getvalue("displayname") } else { $sub } } } . checkregkey "myserver"
now have figured out way use wmi , query registry using stdregprov. there way use in above function?
the reason want have multiple domains in out environment, can pass -credential option gwmi....
i have "stdregprov" returns value of particular key ...not entire hive....
$hklm = 2147483650 $remotecomputer = "someworkstation" $regobject = get-wmiobject -list -namespace root\default | where-object {$_.name -eq "stdregprov"} $key = "software\microsoft\windows\currentversion\uninstall" $value = "domain" $sval= $regobject.getstringvalue($hkeylm,$key,$value)
hi,
try script:
$remotecomputer = "someworkstation"
$reg = get-wmiobject -list -namespace root\default -computername $remotecomputer | where-object {$_.name -eq "stdregprov"}
$hklm = 2147483650
$key = "software\microsoft\windows\currentversion\uninstall"
$subkeys = ($reg.enumkey($hklm,$key)).snames
foreach($subkey in $subkeys)
{
$reg.getstringvalue($hklm,($key+"\"+$subkey),"displayname").svalue;
}
win32_product contain information application installed via msi installer.
Windows Server > Windows PowerShell
Comments
Post a Comment