Last active
June 10, 2020 15:00
-
-
Save pizycki/fbe4d86abcc8d4e3f184a4ac5b588a98 to your computer and use it in GitHub Desktop.
Restores recycled NuGet Package from Azure Artifacts Recycle bin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################### | |
# Params | |
################################################### | |
$p = "" # eg "bc.cqrs" | |
$v = "" # eg "3.1.0.48-featureupdatefluentv" | |
$pat = "" | |
$org = "" | |
$project = "" | |
$feed = "" | |
################################################### | |
# Main | |
################################################### | |
$creds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("user:$pat")) | |
$basicAuth = "Basic $creds" | |
$Headers = @{ | |
Authorization = $basicAuth | |
} | |
################################################### | |
# Get Package | |
################################################### | |
$package = | |
(Invoke-RestMethod ` | |
"https://feeds.dev.azure.com/$org/$project/_apis/Packaging/Feeds/$feed/Packages?packageNameQuery=$p&includeDeleted=true" ` | |
-Method Get ` | |
-Headers $Headers | |
).value ` | |
| ? { $_.name -eq $p } | |
$package | |
################################################### | |
# Get Package Version | |
################################################### | |
$packageVersion = ` | |
(Invoke-RestMethod "https://feeds.dev.azure.com/$org/$project/_apis/Packaging/Feeds/$feed/Packages/$($package.id)/Versions?isDeleted=true" -Method Get -Headers $Headers).value ` | |
| ? { $_.normalizedVersion -eq $v } | |
$packageVersion | |
################################################### | |
# Restore Package Version | |
################################################### | |
$payload = [PSCustomObject]@{ | |
deleted = $false | |
} | ConvertTo-Json | |
$url = "https://pkgs.dev.azure.com/$org/$project/_apis/packaging/feeds/$feed/nuget/RecycleBin/packages/$($package.normalizedName)/versions/$($packageVersion.normalizedVersion)?api-version=5.1-preview.1" | |
$url | |
Invoke-RestMethod $url ` | |
-Method Patch ` | |
-Body $payload ` | |
-Headers $Headers ` | |
-ContentType "application/json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment