-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathUnpublish-AWSPowerShellVersion.ps1
72 lines (61 loc) · 2.36 KB
/
Unpublish-AWSPowerShellVersion.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
<#
.Synopsis
Unlists the specified version of all AWS Tools for PowerShell modules
.Description
Unlists the specified version of all AWS Tools for PowerShell modules.
This includes AWSPowerShell, AWSPowerShell.NetCore, and all of the AWS.Tools.* modules.
This does not include AWS.Tools.Installer.
.Notes
The script must be run from the project root so that it could resolve the path
to the modules folder to loop over all services.
.Example
.\buildtools\Unpublish-AWSPowerShellVersion.ps1 -Version 4.1.121 -ApiKey "apiKey" -DryRun $false
#>
[CmdletBinding()]
Param (
# The version of AWS Tools for PowerShell to unlist, e.g. "4.1.121"
[Parameter(Mandatory = $true)]
[string]$Version,
# API Key for PowerShell gallery
[Parameter(Mandatory = $true)]
[string] $ApiKey,
# Set to false to unlist the modules. By default this will only
# print the commands that will be run.
[Parameter()]
[bool] $DryRun = $true
)
# Helper function that unlists a single module
function Unpublish-AWSPowerShellModule {
param (
$Name,
$Version,
$ApiKey,
$DryRun
)
$deleteCommand = "dotnet nuget delete $Name $Version -s https://www.powershellgallery.com --api-key $ApiKey --non-interactive"
if ($DryRun)
{
Write-Host $deleteCommand
}
else
{
Invoke-Expression $deleteCommand
}
}
# First unlist the service-specific modules
$modules = Get-ChildItem ./modules/AWSPowerShell/Cmdlets
foreach ($module in $modules)
{
$name = "AWS.Tools." + $module.Name
# We've never published modular versions of these, see https://github.com/aws/aws-tools-for-powershell/issues/33
# Despite it being listed in that issue as an exception, it appears we have since published ELB
if (($name -eq "AWS.Tools.CloudHSM") -or ($name -eq "AWS.Tools.CloudWatchEvents") -or ($name -eq "AWS.Tools.KinesisAnalytics"))
{
continue
}
Unpublish-AWSPowerShellModule -Name $name -Version $version -ApiKey $apiKey -DryRun $dryRun
}
# Then monoliths and Common
Unpublish-AWSPowerShellModule -Name "AWSPowerShell" -Version $version -ApiKey $apiKey -DryRun $dryRun
Unpublish-AWSPowerShellModule -Name "AWSPowerShell.NetCore" -Version $version -ApiKey $apiKey -DryRun $dryRun
Unpublish-AWSPowerShellModule -Name "AWS.Tools.Common" -Version $version -ApiKey $apiKey -DryRun $dryRun