Export/Private/New-ApplicationGatewayIpConfiguration.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
61
62
63
64
65
function Global:New-ApplicationGatewayIpConfigurations {
    <#
    .SYNOPSIS
    ...
     
    .EXAMPLE
    ...
     
    .PARAMETER xxx
    ...
    #>

    [CmdletBinding()]    
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceGroupName,
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceLocation,
        [Parameter(Mandatory = $true)]
        [string]
        $FrontEndIpConfigNamePrivate,
        [Parameter(Mandatory = $true)]
        [string]
        $FrontEndIpConfigNamePublic,
        [Parameter(Mandatory = $true)]
        [string]
        $PublicIpAddressName,
        [Parameter(Mandatory = $false)]
        [string]
        $PublicIpAddressSku = "Standard",
        [Parameter(Mandatory = $false)]
        [ValidateSet('Dynamic', 'Static')]
        [string]
        $PublicIpAddressAllocation = "Static",
        [Parameter(Mandatory = $true)]
        [string]
        $PrivateIpAddress,
        [Parameter(Mandatory = $false)]
        [ValidateSet('IPv4', 'IPv6')]
        [string]
        $PrivateIpAddressVersion = 'IPv4',
        $Subnet
    )
    process {
        Write-Verbose "Adding FrontendIP-Configuration..."
        $Ipconfiguration = @{
            Private    = $null
            Public     = $null
            PIP        = $null
            Collection = @()
        }
        $Ipconfiguration.PIP = Get-AzPublicIpAddress -ResourceGroupName $ResourceGroupName -Name $PublicIpAddressName -ErrorAction SilentlyContinue
        if (-not($Ipconfiguration.PIP)) {
            Write-Verbose "Adding Public-IP..."
            $Ipconfiguration.PIP = New-AzPublicIpAddress -ResourceGroupName $ResourceGroupName -Name $PublicIpAddressName -location $ResourceLocation -AllocationMethod $PublicIpAddressAllocation -Sku $PublicIpAddressSku
        }
        $Ipconfiguration.Private = New-AzApplicationGatewayFrontendIPConfig -Name $FrontEndIpConfigNamePrivate -Subnet $Subnet -PrivateIPAddress $PrivateIpAddress
        $Ipconfiguration.Public = New-AzApplicationGatewayFrontendIPConfig -Name $FrontEndIpConfigNamePublic -PublicIPAddress $Ipconfiguration.PIP
        $Ipconfiguration.Collection += ($Ipconfiguration.Private,$Ipconfiguration.Public)
        $Ipconfiguration
    }
}