This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathGet-InstalledSoftware.ps1
124 lines (107 loc) · 4.25 KB
/
Get-InstalledSoftware.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
###############################################################################################################
# Language : PowerShell 4.0
# Filename : Get-InstalledSoftware.ps1
# Autor : BornToBeRoot (https://github.com/BornToBeRoot)
# Description : Get all installed software with DisplayName, Publisher and UninstallString
# Repository : https://github.com/BornToBeRoot/PowerShell
###############################################################################################################
<#
.SYNOPSIS
Get all installed software with DisplayName, Publisher and UninstallString
.DESCRIPTION
Get all installed software with DisplayName, Publisher and UninstallString from a local or remote computer. The result will also include the InstallLocation and the InstallDate. To reduce the results, you can use the parameter "-Search *PRODUCTNAME*".
.EXAMPLE
Get-InstalledSoftware
.EXAMPLE
Get-InstalledSoftware -Search "*chrome*"
DisplayName : Google Chrome
Publisher : Google Inc.
UninstallString : "C:\Program Files (x86)\Google\Chrome\Application\51.0.2704.103\Installer\setup.exe" --uninstall --multi-install --chrome --system-level
InstallLocation : C:\Program Files (x86)\Google\Chrome\Application
InstallDate : 20160506
.EXAMPLE
Get-InstalledSoftware -Search "*firefox*" -ComputerName TEST-PC-01
DisplayName : Mozilla Firefox 47.0.1 (x86 de)
Publisher : Mozilla
UninstallString : "C:\Program Files (x86)\Mozilla Firefox\uninstall\helper.exe"
InstallLocation : C:\Program Files (x86)\Mozilla Firefox
InstallDate :
.LINK
https://github.com/BornToBeRoot/PowerShell/blob/master/Documentation/Function/Get-InstalledSoftware.README.md
#>
function Get-InstalledSoftware
{
[CmdletBinding()]
param(
[Parameter(
Position=0,
HelpMessage='Search for product name (You can use wildcards like "*ProductName*')]
[String]$Search,
[Parameter(
Position=1,
HelpMessage='ComputerName or IPv4-Address of the remote computer')]
[String]$ComputerName = $env:COMPUTERNAME,
[Parameter(
Position=2,
HelpMessage='Credentials to authenticate agains a remote computer')]
[System.Management.Automation.PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential
)
Begin{
$LocalAddress = @("127.0.0.1","localhost",".","$($env:COMPUTERNAME)")
[System.Management.Automation.ScriptBlock]$ScriptBlock = {
# Location where all entrys for installed software should be stored
return Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Select-Object -Property DisplayName, Publisher, UninstallString, InstallLocation, InstallDate
}
}
Process{
if($LocalAddress -contains $ComputerName)
{
$Strings = Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Search
}
else
{
if(Test-Connection -ComputerName $ComputerName -Count 2 -Quiet)
{
try {
if($PSBoundParameters.ContainsKey('Credential'))
{
$Strings = Invoke-Command -ScriptBlock $ScriptBlock -ComputerName $ComputerName -ArgumentList $Search -Credential $Credential -ErrorAction Stop
}
else
{
$Strings = Invoke-Command -ScriptBlock $ScriptBlock -ComputerName $ComputerName -ArgumentList $Search -ErrorAction Stop
}
}
catch {
throw
}
}
else
{
throw """$ComputerName"" is not reachable via ICMP!"
}
}
foreach($String in $Strings)
{
# Check for each entry if data exists
if((-not([String]::IsNullOrEmpty($String.DisplayName))) -and (-not([String]::IsNullOrEmpty($String.UninstallString))))
{
# Search (only if parameter is used)
if((-not($PSBoundParameters.ContainsKey('Search'))) -or (($PSBoundParameters.ContainsKey('Search') -and ($String.DisplayName -like $Search))))
{
[pscustomobject] @{
DisplayName = $String.DisplayName
Publisher = $String.Publisher
UninstallString = $String.UninstallString
InstallLocation = $String.InstallLocation
InstallDate = $String.InstallDate
}
}
}
}
}
End{
}
}