-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Get-WinGetPackage.ps1
133 lines (111 loc) · 4.75 KB
/
Get-WinGetPackage.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
Function Get-WinGetPackage{
<#
.SYNOPSIS
Gets installed packages on the local system. displays the packages installed on the system, as well as whether an update is available.
Additional options can be provided to filter the output, much like the search command.
.DESCRIPTION
By running this cmdlet with the required inputs, it will retrieve the packages installed on the local system.
.PARAMETER Filter
Used to search across multiple fields of the package.
.PARAMETER Id
Used to specify the Id of the package
.PARAMETER Name
Used to specify the Name of the package
.PARAMETER Moniker
Used to specify the Moniker of the package
.PARAMETER Tag
Used to specify the Tag of the package
.PARAMETER Command
Used to specify the Command of the package
.PARAMETER Count
Used to specify the maximum number of packages to return
.PARAMETER Exact
Used to specify an exact match for any parameters provided. Many of the other parameters may be used for case-insensitive substring matches if Exact is not specified.
.PARAMETER Source
Name of the Windows Package Manager private source. Can be identified by running: "Get-WinGetSource" and using the source Name
.PARAMETER Header
Used to specify the value to pass as the "Windows-Package-Manager" HTTP header for a REST source.
.PARAMETER AcceptSourceAgreement
Used to accept any source agreements required by a REST source.
.EXAMPLE
Get-WinGetPackage -id "Publisher.Package"
This example expects only a single configured REST source with a package containing "Publisher.Package" as a valid identifier.
.EXAMPLE
Get-WinGetPackage -id "Publisher.Package" -source "Private"
This example expects the REST source named "Private" with a package containing "Publisher.Package" as a valid identifier.
.EXAMPLE
Get-WinGetPackage -Name "Package"
This example expects the REST source named "Private" with a package containing "Package" as a valid name.
#>
PARAM(
[Parameter(Position=0)] $Filter,
[Parameter()] $Name,
[Parameter()] $Id,
[Parameter()] $Moniker,
[Parameter()] $Tag,
[Parameter()] $Source,
[Parameter()] $Command,
[Parameter()] [ValidateRange(1, [int]::maxvalue)][int]$Count,
[Parameter()] [switch]$Exact,
[Parameter()] [ValidateLength(1, 1024)]$Header,
[Parameter()] [switch]$AcceptSourceAgreement
)
BEGIN
{
[string[]] $WinGetArgs = @("List")
[WinGetPackage[]]$Result = @()
[string[]] $IndexTitles = @("Name", "Id", "Version", "Available", "Source")
if($Filter){
## Search across Name, ID, moniker, and tags
$WinGetArgs += $Filter
}
if($PSBoundParameters.ContainsKey('Name')){
## Search for the Name
$WinGetArgs += "--Name", $Name.Replace("…", "")
}
if($PSBoundParameters.ContainsKey('Id')){
## Search for the ID
$WinGetArgs += "--Id", $Id.Replace("…", "")
}
if($PSBoundParameters.ContainsKey('Moniker')){
## Search for the Moniker
$WinGetArgs += "--Moniker", $Moniker.Replace("…", "")
}
if($PSBoundParameters.ContainsKey('Tag')){
## Search for the Tag
$WinGetArgs += "--Tag", $Tag.Replace("…", "")
}
if($PSBoundParameters.ContainsKey('Source')){
## Search for the Source
$WinGetArgs += "--Source", $Source.Replace("…", "")
}
if($PSBoundParameters.ContainsKey('Count')){
## Specify the number of results to return
$WinGetArgs += "--Count", $Count
}
if($Exact){
## Search using exact values specified (case-sensitive)
$WinGetArgs += "--Exact"
}
if($PSBoundParameters.ContainsKey('Header')){
## Pass the value specified as the Windows-Package-Manager HTTP header
$WinGetArgs += "--header", $Header
}
if($AcceptSourceAgreement){
## Accept source agreements
$WinGetArgs += "--accept-source-agreements"
}
}
PROCESS
{
$List = Invoke-WinGetCommand -WinGetArgs $WinGetArgs -IndexTitles $IndexTitles
foreach ($Obj in $List) {
$Result += [WinGetPackage]::New($Obj)
}
}
END
{
return $Result
}
}
Export-ModuleMember -Function Get-WinGetPackage