-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathGet-Program.ps1
executable file
·98 lines (74 loc) · 2.86 KB
/
Get-Program.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
function Get-Program {
<#
.Synopsis
Generates a list of installed programs on a computer
.DESCRIPTION
This function generates a list by querying the registry and returning the installed programs of a local or remote computer.
.NOTES
Name: Get-Program
Author: Nick Rodriguez
.PARAMETER ComputerName
The computer to which connectivity will be checked
.PARAMETER DisplayName
The program name to search for (supports wildcards)
.PARAMETER CSVExportPath
If used, results will be exported to a CSV with the given path
.EXAMPLE
Get-Program -DisplayName 'Microsoft*'
Description:
Will generate a list of installed programs with DisplayName starting with Microsoft on local machine
.EXAMPLE
Get-Program -ComputerName server01, server02 -DisplayName 'Adobe*'
Description:
Will generate a list of installed programs with DisplayName starting with Adobe on server01 and server02
.EXAMPLE
Get-Program -ComputerName Server01
Description:
Will gather the list of programs from Server01 and their properties
.EXAMPLE
'server01', 'server02' | Get-Program
Description
Will retrieve the installed programs on server01/02 that are passed on to the function through the pipeline and also retrieves the uninstall string for each program
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position = 0
)]
[string[]]$ComputerName = $env:COMPUTERNAME,
[string]$DisplayName = '*',
[string]$CSVExportPath,
[pscredential]$Credential
)
begin {
$Programs = @()
$ScriptBlock = {
[cmdletbinding()]
param (
[string]$DisplayName
)
$RegistryLocation = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
)
foreach ($CurrentReg in $RegistryLocation) {
Get-ChildItem -Path $CurrentReg | ForEach-Object {
Get-ItemProperty -Path "HKLM:\$_" | Where-Object { $_.DisplayName -like $DisplayName }
}
}
}
}
process {
$Programs = if ($Credential) {
Write-Verbose 'Credentials provided'
Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ArgumentList $DisplayName -Credential $Credential
} else {
Write-Verbose 'Credentials not provided'
Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ArgumentList $DisplayName
}
if ($CSVExportPath) { $Programs | Export-Csv -Path $CSVExportPath -NoTypeInformation -Append }
Write-Output $Programs
}
}