git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/AzureHelpers/Public/Show-AzGroup.ps1
blob: 7de8bfa41c6b9e57d552ec0b505df99139890451 (plain)
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
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}'
}