functions/Get-jtAzProviderNamespace.ps1

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
58
59
60
function Get-jtAzProviderNamespace {
<#
.SYNOPSIS
    Returns all the provider namespaces found on https://docs.microsoft.com/en-us/azure/templates/

.DESCRIPTION
    Get-jtAzProviderNamespace is a function that returns the all the provider namespaces found at https://docs.microsoft.com/en-us/azure/templates/.

.PARAMETER Name
    The provider namespace you are searching for. Can be any string.

.EXAMPLE
     Get-jtAzProviderNamespace

.EXAMPLE
     Get-jtAzProviderNamespace -Name sql

.INPUTS
    String

.OUTPUTS
    String

.NOTES
    Author: Jeroen Trimbach
    Website: https://jeroentrimbach.com
#>

    param (
        [Parameter(Position=0,Mandatory=$false)]
        [string]$Name
    )
    BEGIN {
        Write-Verbose "Starting: $($MyInvocation.MyCommand)"
    }
    PROCESS {
        try {
            $response = Invoke-RestMethod -Uri https://docs.microsoft.com/en-us/azure/templates/breadcrumb/toc.json
            $items = $response.items.children.children.children |
                ForEach-Object {
                    $words = $_.href.replace('/azure/templates/','').Split('/')
                    $words[0]
            }
            if ($PSBoundParameters.ContainsKey('Name')) {
                Write-Output $items |
                    Select-Object -Unique |
                    Where-object {$_ -match $Name} |
                    Sort-Object
            } else {
                Write-Output $items |
                    Select-Object -Unique |
                    Sort-Object
            }
        } catch {
            Write-Warning "FAILED to return provider namespace(s)"
        }
    }
    END {
        Write-Verbose "Ending: $($MyInvocation.MyCommand)"
    }
}