-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew_PublicIpAddress.ps1
More file actions
60 lines (59 loc) · 2.74 KB
/
New_PublicIpAddress.ps1
File metadata and controls
60 lines (59 loc) · 2.74 KB
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 New-PublicIpAddress {
[CmdletBinding()]
param (
[Parameter(
Position = 0,
Mandatory = $true,
HelpMessage = 'Provide the resource group name in where the resources is to be created'
)]
[string]$ResourceGroupName,
[Parameter(
Position = 1,
Mandatory = $true,
HelpMessage = 'Provide the location for resources to be created'
)]
[string]$Location,
[Parameter(
Position = 6,
Mandatory = $true,
HelpMessage = 'Provide the name of public ip address to be created'
)]
[string]$PublicIpAddressName,
[Parameter(
Position = 7,
Mandatory = $true,
HelpMessage = 'Provide the DomainNameLabel of public ip address to be created,its should be globally unique'
)]
[string]$PublicIpDomainNameLabel
)
write-Output '*************************************************************************************************************************************************************'
try {
Write-Output ('Checking if a PublicIP already exists with the name : {0}' -f $PublicIpAddressName)
$PublicIP = Get-AzPublicIpAddress -ResourceGroupName $ResourceGroupName -Name $PublicIpAddressName -ErrorAction SilentlyContinue
if (-not $PublicIP) {
write-Output $ManageIdentityName 'STARTED: Creating the Public IP Address'
write-Output '_______________________________________________________________________________________________________________________________________________________________'
$PublicIpAddressParam = @{
ResourceGroupName = $ResourceGroupName
Name = $PublicIpAddressName
Location = $Location
AllocationMethod = 'Static'
Sku = 'Standard'
IpAddressVersion = 'IPv4'
DomainNameLabel = $PublicIpDomainNameLabel
}
$PublicIP = New-AzPublicIpAddress @PublicIpAddressParam -ErrorAction SilentlyContinue
write-Output $PublicIP
write-Output '_______________________________________________________________________________________________________________________________________________________________'
write-Output $ManageIdentityName 'COMPLETED: Creating the Public IP Address'
}
else {
Write-Output ('A PublicIP already exists with the name : {0}' -f $PublicIpAddressName)
}
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
throw
}
write-Output '*************************************************************************************************************************************************************'
}