Wednesday, June 10, 2009

Listing Add/Remove Programs with Powershell, redux

Man, I barely get the thing posted, and already there's complaints about having to install stuff.

Okay, fine:

$target = "somecomputer"

$arp_key = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $target)

$regkey = $hive.OpenSubKey($arp_key)

foreach( $subkey_name in $regkey.GetSubKeyNames() )
{
$subkey = $hive.OpenSubKey( $arp_key + "\" + $subkey_name )
$display_name = $subkey.GetValue( "DisplayName" )
$display_version = $subkey.GetValue( "DisplayVersion" )

if( $display_name -ne [string].Empty )
{
write-host @($display_name + " (" + $display_version + ")")
}

# foreach( $val_name in $subkey.GetValueNames() )
# {
# write-host "name: " $val_name -nonewline */
# write-host "value: " $subkey.GetValue( $val_name )
# }
}


No installation required. It is rather naive - if there is no display name, then it is skipped. If you've got a better version, please let me know. This one feels icky, to me.

I left in a chunk, remarked out, to show how to get to the other values.

No comments:

Post a Comment