-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathARM - Network Interface (NIC) - Remove Public IP.ps1
85 lines (42 loc) · 1.64 KB
/
ARM - Network Interface (NIC) - Remove Public IP.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
## To Set Verbose output
$PSDefaultParameterValues['*:Verbose'] = $true
# Variables - Resource Group
$rgShortName = "qweasdzxc"
$rgSuffix = "-rg"
$rgName = "${rgShortName}${rgSuffix}"
# Variables - Network Interface (NIC)
$nicShortName = "qweasdzxc"
$nicSuffix = "-nic"
$nicName = "${nicShortName}${nicSuffix}"
$subnetName = "WebSubnet"
# Variables - Public IP
$publicIpShortName = "qweasdzxc2"
$publicIpSuffix = "-ip"
$publicIpName = "${publicIpShortName}${publicIpSuffix}"
<# Network Interface (NIC) - Remove Public IP #>
# NOTE: It only remove Public IP Address assignment from NIC's IP Config
<#
Network Interface (NIC)
Public IP address (Not required)
#>
Get-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -ErrorVariable isNICExist -ErrorAction SilentlyContinue `
If (!$isNICExist)
{
Write-Output "Network Interface (NIC) exist"
Write-Verbose "Fetching Network Interface (NIC): {$nicName}"
$nic = Get-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName
Write-Verbose "Removing Public IP from Network Interface (NIC): {$nicName}"
# Featch first IP configuration
$nic.IpConfigurations[0].PublicIpAddress = $null
Set-AzureRmNetworkInterface -NetworkInterface $nic
# NOT WORKING
#Remove-AzureRmNetworkInterfaceIpConfig -Name $publicIpName -NetworkInterface $nic
}
Else
{
Write-Output "Network Interface (NIC) does not exist"
}
<#
## References
https://docs.microsoft.com/en-us/powershell/module/azurerm.network/remove-azurermnetworkinterfaceipconfig?view=azurermps-6.13.0
#>