-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathGet-Installed.ps1
173 lines (147 loc) · 5.3 KB
/
Get-Installed.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<#
.SYNOPSIS
Report all installed applications registered on the local system.
.PARAMETER OutFile
The name of a CSV file to create. Default is to write to the console.
.PARAMETER Store
Include Microsoft Store applications.
.DESCRIPTION
When writing to the console, the number of column in the report is
governed by the width of the console. When writing to CSV file, all
possible columns are reported.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[switch] $Store,
[string] $OutFile
)
Begin
{
$esc = [char]27
function CollectKnownApplicationKeys
{
$root64 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
$root32 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
# enumerate HKLM\SOFTWARE\...
# note this will be redirected to Wow6432Node if running from 32-bit on 64-bit Windows
$appkeys = (Get-ChildItem $root64).Name | foreach { $_.replace('HKEY_LOCAL_MACHINE', 'HKLM:') }
# enumerate HKLM\SOFTWARE\Wow6432Node\...
$wowkeys = (Get-ChildItem $root32).Name | foreach { $_.replace('HKEY_LOCAL_MACHINE', 'HKLM:') }
# join unique
$appkeys += $wowkeys | where { $appkeys -notcontains (Join-Path $root64 (Split-Path $_ -leaf)) }
$appkeys
}
function ExpandAppDetails
{
param([Parameter(ValueFromPipeline = $true)] [string] $key)
Process
{
$item = Get-Item $key
$name = $item.GetValue('DisplayName')
if ([String]::IsNullOrWhiteSpace($name)) { return $null }
#filter out updates and service packs
if (($name -ccontains 'Update for') -or ($name -contains 'Service Pack')) { return $null }
#filter out system components; these are usually windows updates
$syscomp = $item.GetValue('SystemComponent')
if ($syscomp) { if ($syscomp -eq 1) { return $null } }
$installDate = $item.GetValue('InstallDate')
if (-not [String]::IsNullOrWhiteSpace($installDate))
{
$installDate = $installDate.Substring(4, 2) + '/' + $installDate.Substring(6, 2) + '/' + $installDate.Substring(0, 4)
}
# If subkey's name is in Wow6432Node, then the application is 32-bit. Otherwise,
# $is64Bit determines whether the application is 32-bit or 64-bit.
$arch = '64-bit'
if ($key -match 'Wow6432Node') { $arch = '32-bit' }
New-Object PSObject -Property @{
#ComputerName = $computerName
#Subkey = (split-path $key -parent) # useful when debugging
AppID = (Split-Path $key -leaf)
DisplayName = $name
Publisher = $item.GetValue('Publisher')
DisplayVersion = $item.GetValue('DisplayVersion')
Date = $installDate
Architecture = $arch
Store = $false
}
}
}
function CollectKnownAppXKeys
{
$0 = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages'
(Get-ChildItem $0 | where `
{
$_.GetValue('DisplayName') -notmatch 'ms-resource' -and
$_.GetValue('SupportedUsers') -eq 0
}).Name | foreach { $_.replace('HKEY_CURRENT_USER', 'HKCU:') }
}
function ExpandAppXDetails
{
param([Parameter(ValueFromPipeline = $true)] [string] $key)
Process
{
$item = Get-Item $key
$name = $item.GetValue('DisplayName')
$users = $item.GetValue('SupportedUsers')
if (($name -notmatch '^ms-resource:.*') -and $users -eq 0)
{
$packID = $item.GetValue('PackageID')
$path = "$($env:ProgramFiles)\Windowsapps\$packID"
if (Test-Path $path)
{
$xmlpath = Join-Path $path 'AppXManifest.xml'
if (Test-Path $xmlpath)
{
[xml]$manifest = Get-Content $xmlpath
$version = $manifest.Package.Identity.Version
$publisher = $manifest.Package.Properties.PublisherDisplayName
$arch = $manifest.Package.Identity.ProcessorArchitecture -match '64'
}
New-Object PSObject -Property @{
AppID = $packID
DisplayName = "$name (`$)"
Publisher = $publisher
DisplayVersion = $version
Date = (Get-Item $path).CreationTime.ToShortDateString()
Architecture = @('64-bit','32-bit')[$arch]
Store = $true
}
}
}
}
}
function MakeExpression
{
param($store, $value)
if ($store) { $color = '90' } else { $color = '37' }
"$esc[$color`m$($value)$esc[0m"
}
}
Process
{
$confirm = [IO.Path]::Combine((Split-Path -parent $PSCommandPath), 'Test-Elevated.ps1')
if (!(. $confirm (Split-Path -Leaf $PSCommandPath) -warn)) { return }
$apps = CollectKnownApplicationKeys | ExpandAppDetails | where { $_ -ne $null }
if ($Store)
{
$apps += (CollectKnownAppXKeys | ExpandAppXDetails)
}
$apps = $apps | Select-Object DisplayName, DisplayVersion, Date, Publisher, Architecture, AppID, Store | `
Sort -Property DisplayName
if ($OutFile -ne $null -and $OutFile.Length -gt 0)
{
$apps | Export-Csv -Path $OutFile
}
else
{
# use 'Get-Colors -all' command to fine DOS [esc color numbers
$apps | Format-Table `
@{ Label = 'Name'; Expression = { MakeExpression $_.Store $_.DisplayName } },
@{ Label = 'Version'; Expression = { MakeExpression $_.Store $_.DisplayVersion } },
@{ Label = 'Date'; Expression = { MakeExpression $_.Store $_.Date } },
@{ Label = 'Publisher'; Expression = { MakeExpression $_.Store $_.Publsher } },
@{ Label = 'Architecture'; Expression = { MakeExpression $_.Store $_.Architecture } },
@{ Label = 'AppID'; Expression = { MakeExpression $_.Store $_.AppID } } `
-AutoSize
}
}