git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/AzureHelpers/Public/Show-AzGroup.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'AzureHelpers/Public/Show-AzGroup.ps1')
-rw-r--r--AzureHelpers/Public/Show-AzGroup.ps157
1 files changed, 57 insertions, 0 deletions
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