Get-ProgID.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function Get-ProgID {
    <#
    .Synopsis
       Gets all of the ProgIDs registered on a system
    .Description
       Gets all ProgIDs registered on the system. The ProgIDs returned can be used with New-Object -comObject
    .Example
       Get-ProgID
    .Example
        Get-ProgID *Image*
    #>

    param(
    [String]$ProgId = "*"
    )            
    $paths = @("REGISTRY::HKEY_CLASSES_ROOT\CLSID")            
    if ($env:Processor_Architecture -eq "amd64") {            
        $paths+="REGISTRY::HKEY_CLASSES_ROOT\Wow6432Node\CLSID"            
    }             
    Get-ChildItem $paths -include VersionIndependentPROGID -recurse |
    Where-Object { $_.GetValue("") -like $ProgId } |
    Select-Object @{            
        Name='ProgID'            
        Expression={$_.GetValue("")}                    
    }, @{
        Name='Library'
        Expression={
            $inProcServer = Get-ItemProperty "$($_.PSParentPath)\InProcServer32" | Select-Object -ExpandProperty '(default)'                
            if ($inProcServer) { $inProcServer } else {
                Get-ItemProperty "$($_.PSParentPath)\LocalServer32" | Select-Object -ExpandProperty '(default)'                
            }
        }
    },@{            
        Name='32Bit'            
        Expression={            
            if ($env:Processor_Architecture -eq "amd64") {            
                $_.PSPath.Contains("Wow6432Node")                
            } else {            
                $true            
            }                        
        }            
    }            
}