Created
April 1, 2022 20:18
-
-
Save Jaykul/88900be0cf36ab6d340d65a4ffd056b3 to your computer and use it in GitHub Desktop.
Search for repositories and get the latest tags
This file contains 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
using namespace System.Collections.Generic | |
using namespace Microsoft.Azure.Commands.ContainerRegistry.Models | |
filter Get-AcrTag { | |
[Alias("Get-BicepTag","gat","gbt")] | |
[CmdletBinding()] | |
param( | |
# The (partial) name of the repository. | |
[Parameter(Mandatory, ValueFromRemainingArguments, Position = 0)] | |
[Alias("RepositoryName")] | |
[string[]]$Name, | |
# The name of the registry to search. | |
# Recommend you set this in your $PSDefaultParameters | |
[Parameter(Mandatory)] | |
[string]$RegistryName, | |
# Force fetching the list of repositories from the registry | |
[switch]$Force | |
) | |
$global:AzContainerRegistryRepositoryCache += @{} | |
if (!$Force -and $AzContainerRegistryRepositoryCache.ContainsKey($RegistryName)) { | |
Write-Verbose "Using cached repository list (specify -Force to re-fetch)" | |
} else { | |
Write-Verbose "Looking for new repositories" | |
$global:AzContainerRegistryRepositoryCache[$RegistryName] = Get-AzContainerRegistryRepository -RegistryName $RegistryName | |
} | |
$Repositories = $global:AzContainerRegistryRepositoryCache[$RegistryName] -match "($($name -join '|'))$" | |
foreach ($repo in $Repositories) { | |
Write-Verbose "Fetching version tags for $repo" | |
foreach($registry in Get-AzContainerRegistryTag -RegistryName crbicepazusw2dvorprd -RepositoryName $repo -ea 0) { | |
# Sort the tags the opposite direction | |
$registry.Tags.Sort( { -1 * $args[0].LastUpdateTime.CompareTo($args[1].LastUpdateTime) } ) | |
$registry | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment