This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathSave-PSResource.ps1
More file actions
164 lines (144 loc) · 6.51 KB
/
Save-PSResource.ps1
File metadata and controls
164 lines (144 loc) · 6.51 KB
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
# Saving resources
function Save-PSResource {
[OutputType([void])]
[cmdletbinding(SupportsShouldProcess = $true)]
Param
(
# Specifies the exact names of resources to save from a repository.
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'NameAndLiteralPathParameterSet')]
[ValidateNotNullOrEmpty()]
[string[]]
$Name,
# Specifies the type of the resource being saved.
[Parameter(ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(ParameterSetName = 'NameAndLiteralPathParameterSet')]
[ValidateSet('Module', 'Script', 'Library')]
[string[]]
$Type,
# Used for pipeline input.
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'InputObjectAndPathParameterSet')]
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'InputObjectAndLiteralPathParameterSet')]
[ValidateNotNull()]
[PSCustomObject[]]
$InputObject,
# Specifies the minimum version of the resource to be saved (cannot use this parameter with the RequiredVersion parameter).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndLiteralPathParameterSet')]
[ValidateNotNull()]
[string]
$MinimumVersion,
# Specifies the maximum version of the resource to include to be saved (cannot use this parameter with the RequiredVersion parameter).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndLiteralPathParameterSet')]
[ValidateNotNull()]
[string]
$MaximumVersion,
# Specifies the required version of the resource to include to be saved (cannot use this parameter with the MinimumVersion or MaximumVersion parameters).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndLiteralPathParameterSet')]
[ValidateNotNull()]
[string]
$RequiredVersion,
# Specifies the repository to search within (default is all repositories).
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndLiteralPathParameterSet')]
[ValidateNotNullOrEmpty()]
[string[]]
$Repository,
# Specifies the location on the local computer to store a saved resource. Accepts wildcard characters.
[Parameter(Mandatory = $true,
Position = 1,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(Mandatory = $true,
Position = 1,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'InputObjectAndPathParameterSet')]
[string]
$Path,
# Specifies a path to one or more locations.
# The value of the LiteralPath parameter is used exactly as entered. No characters are interpreted as wildcards.
# If the path includes escape characters, enclose them in single quotation marks.
# PowerShell does not interpret any characters enclosed in single quotation marks as escape sequences.
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'NameAndLiteralPathParameterSet')]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'InputObjectAndLiteralPathParameterSet')]
[Alias('PSPath')]
[string]
$LiteralPath,
# Specifies a proxy server for the request, rather than connecting directly to an internet resource.
[Parameter(ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Uri]
$Proxy,
# Specifies a user account that has permission to use the proxy server specified by the Proxy parameter.
[Parameter(ValueFromPipelineByPropertyName = $true)]
[PSCredential]
$ProxyCredential,
# Specifies a user account that has permission to save a resource from a specific repository.
[Parameter(ValueFromPipelineByPropertyName = $true)]
[PSCredential]
$Credential,
# Saves a resource without asking for user confirmation.
[Parameter()]
[switch]
$Force,
# Allows you to save a resource marked as a prerelease.
[Parameter(ParameterSetName = 'NameAndPathParameterSet')]
[Parameter(ParameterSetName = 'NameAndLiteralPathParameterSet')]
[switch]
$Prerelease,
# Automatically accept the license agreement if the resoruce requires it.
[Parameter()]
[switch]
$AcceptLicense,
# Will save the resource as a nupkg (if it was originally a nupkg) instead of expanding it into a folder.
[Parameter()]
[switch]
$AsNupkg,
# Will explicitly retain the runtimes directory hierarchy within the nupkg to the root of the destination.
[Parameter()]
[switch]
$IncludeAllRuntimes
)
begin { }
process {
foreach ($n in $Name) {
if ($pscmdlet.ShouldProcess($n)) {
if (Find-PSResource $n) {
# Save the resource-- use install logic
write-verbose -message "Successfully saved $n"
}
}
}
}
end { }
}