From 1b082205f1e98a084695b042adec5cc122ff7717 Mon Sep 17 00:00:00 2001 From: Harald Pfeiffer Date: Thu, 24 Jul 2025 14:49:27 +0200 Subject: InComm, rather spontaneous --- AzureHelpers/Public/Show-AzGroup.ps1 | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 AzureHelpers/Public/Show-AzGroup.ps1 (limited to 'AzureHelpers/Public/Show-AzGroup.ps1') diff --git a/AzureHelpers/Public/Show-AzGroup.ps1 b/AzureHelpers/Public/Show-AzGroup.ps1 new file mode 100644 index 0000000..7de8bfa --- /dev/null +++ b/AzureHelpers/Public/Show-AzGroup.ps1 @@ -0,0 +1,57 @@ +function Show-AzGroup { + <# + .SYNOPSIS + List details of an Azure resource group containing an input string. + + .DESCRIPTION + We'll find out all resource group inside the subscription we are logged into + which contain the string $GroupName (i.e. 'yGrou' will yield 'myGroup'). + + If we find more than one result, we will throw an exception telling this. + + If there is one match, a more or less terse output will be generated displaying + the group details. + + .INPUTS + String. The resource group name we want to investigate. Part of the name is + sufficient if unambiguous inside the active subscription. + + .OUTPUTS + String. A coloured JSON output showing a more or less terse list of + the resource group's parameters. + #> + [Alias( + 'azgroup', + 'azrg' + )] + Param( + [Parameter( + Mandatory=$true, + ValueFromPipeline=$true, + HelpMessage="String that is a resource group name or is part of one unambiguous RG", + Position=0 + ) + ] + [ValidateLength(1,64)] + [string] + $GroupName + ) + $groups = @() + foreach ($group in (List-AzGroups)) { + if ($group.name.Contains($GroupName)) { + $groups += $group + } + } + switch ($groups.Count) { + 0 { + throw [System.ArgumentNullException]::New("No resource group found with its name containing `"$($GroupName)`"") + } + 1 { + $true | Out-Null + } + Default { + throw [System.ArgumentException]::New("More than one resource group found with their names containing `"$($GroupName)`"") + } + } + az group show -g $group[0].name --query '{id: id, location: location, managedBy: managedBy, properties: properties, tags: tags}' +} \ No newline at end of file -- cgit v1.2.3