-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathARM - Public IP - Delete.ps1
101 lines (54 loc) · 2.12 KB
/
ARM - Public IP - Delete.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<# Public IP Address #>
<#
#>
# Variables - Public IP
$publicIpShortName = "qweasdzxc4"
$publicIpSuffix = "-ip"
$publicIpName = "${publicIpShortName}${publicIpSuffix}"
#$dnsPrefix = "qweasdzxc"
$dnsPrefix = "qweasdzxc$(Get-Random)"
<# Create Public IP Address, if it does not exist #>
Get-AzureRmPublicIpAddress -Name $publicIpName -ResourceGroupName $rgName -ErrorVariable isIPExist -ErrorAction SilentlyContinue `
If ($isIPExist)
{
Write-Output "Public IP does not exist"
Write-Verbose "Creating Public IP: {$publicIpName}"
$publicIp = New-AzureRmPublicIpAddress `
-Name $publicIpName `
-ResourceGroupName $rgName `
-Location $location `
-AllocationMethod 'Static' `
-DomainNameLabel $dnsPrefix `
-Tag $tags
# -AllocationMethod 'Static' ` ## 'Static' 'Dynamic'
}
Else
{
Write-Output "Public IP exist"
Write-Verbose "Fetching Public IP: {$publicIpName}"
$publicIp = Get-AzureRmPublicIpAddress -Name $publicIpName -ResourceGroupName $rgName
}
Write-Verbose "Get list of Public IPs"
Write-Output "Public IP"
Get-AzureRmPublicIpAddress -ResourceGroupName $rgName `
| Select-Object Name, IpAddress, @{label='FQDN';expression={$_.DnsSettings.Fqdn}}, ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap
<#
Get-AzureRmPublicIpAddress `
| Select-Object Name, ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap -GroupBy ResourceGroupName
#>
<#
## Remove Public Ip
$publicIpShortName = "qweasdzxc"
$publicIpSuffix = "-ip"
$publicIpName = "${publicIpShortName}${publicIpSuffix}"
Write-Verbose "Deleting Public Ip: {$publicIpName}"
Remove-AzureRmPublicIpAddress -Name $publicIpName -ResourceGroupName $rgName -Force
#>
<#
## References
https://docs.microsoft.com/en-us/powershell/module/azurerm.network/new-azurermpublicipaddress?view=azurermps-6.13.0
https://docs.microsoft.com/en-us/powershell/module/azurerm.network/get-azurermpublicipaddress?view=azurermps-6.13.0
#>