forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemove-ADOArtifactFeed.ps1
108 lines (99 loc) · 3.82 KB
/
Remove-ADOArtifactFeed.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
function Remove-ADOArtifactFeed
{
<#
.Synopsis
Removes artifact feeds from Azure DevOps
.Description
Removes artifact feeds from Azure DevOps. Artifact feeds are used to publish packages.
.Link
https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/create%20feed?view=azure-devops-rest-5.1
.Example
Get-ADOArtifactFeed -Organization MyOrg -Project MyProject -FeedId MyFeed |
Remove-ADOArtifactFeed
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
"PSPossibleIncorrectComparisonWithNull", "", Justification="Explicitly checking for nulls"
)]
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact='High',
DefaultParameterSetName='packaging/feeds/{feedId}'
)]
[OutputType([Nullable],[Collections.IDictionary])]
param(
# The Organization
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('Org')]
[string]
$Organization,
# The Project
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$Project,
# The Feed Name or ID
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[ValidatePattern(
#?<> -LiteralCharacter '|?/\:&$*"[]>' -CharacterClass Whitespace -Not -Repeat -StartAnchor StringStart -EndAnchor StringEnd
'\A[^\s\|\?\/\\\:\&\$\*\"\[\]\>]+\z'
)]
[Alias('FullyQualifiedID')]
[string]
$FeedID,
# The View Name or ID
[Parameter(ValueFromPipelineByPropertyName)]
[ValidatePattern(
#?<> -LiteralCharacter '|?/\:&$*"[]>' -CharacterClass Whitespace -Not -Repeat -StartAnchor StringStart -EndAnchor StringEnd
'\A[^\s\|\?\/\\\:\&\$\*\"\[\]\>]{0,}\z'
)]
[string]
$ViewID,
# If set, will remove a view.
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='packaging/feeds/{feedId}/views/{viewId}')]
[switch]
$View,
# The server. By default https://feeds.dev.azure.com/.
[Parameter(ValueFromPipelineByPropertyName)]
[uri]
$Server = "https://feeds.dev.azure.com/",
# The api version. By default, 5.1-preview.
[string]
$ApiVersion = "5.1-preview")
dynamicParam { . $GetInvokeParameters -DynamicParameter }
begin {
#region Copy Invoke-ADORestAPI parameters
$invokeParams = . $getInvokeParameters $PSBoundParameters
#endregion Copy Invoke-ADORestAPI parameters
}
process {
$parameterSetName = $psCmdlet.ParameterSetName
if (-not $ViewID) {
$parameterSetName = $MyInvocation.MyCommand.DefaultParameterSet
}
$invokeParams.Uri = # First construct the URI. It's made up of:
"$(@(
"$server".TrimEnd('/') # * The Server
$Organization # * The Organization
$(if ($Project) { $Project }) # * The Project
'_apis' #* '_apis'
. $ReplaceRouteParameter $parameterSetName #* and the replaced route parameters.
) -join '/')?$( # Followed by a query string, containing
@(
if ($Server -ne 'https://feeds.dev.azure.com/' -and
-not $PSBoundParameters.ApiVersion) {
$ApiVersion = '2.0'
}
if ($ApiVersion) { # an api-version (if one exists)
"api-version=$ApiVersion"
}
) -join '&'
)"
$invokeParams.Method = 'DELETE'
if ($WhatIfPreference) {
$invokeParams.Remove('PersonalAccessToken')
return $invokeParams
}
if ($PSCmdlet.ShouldProcess("$($invokeParams.Method) $($invokeParams.Uri)")) {
$null = Invoke-ADORestAPI @invokeParams
}
}
}