-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppGwManagementOperations.ps1
77 lines (73 loc) · 3.31 KB
/
AppGwManagementOperations.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
function login()
{
Add-AzAccount
$SubscriptionID = Read-Host -Prompt "Enter the Azure Subscription ID"
Select-AzSubscription -SubscriptionId $SubscriptionID
$(ResourceDetails)
}
function ResourceDetails()
{
$APPGWName = Read-Host -Prompt "Enter Application Gateway Name"
$RGName = Read-Host -Prompt "Enter the Resource Group Name"
$(state)
}
function state()
{
$APPGW = Get-AzApplicationGateway -Name $APPGWName -ResourceGroupName $RGName
if($APPGW.ProvisioningState -eq "Failed")
{
Write-Host The Application Gateway $APPGW.Name is in FAILED State. However, you would still be able to access Application. Allow us few minutes to update the App Gateway status -BackgroundColor DarkRed -ForegroundColor White
Write-Host We have started updating the status for $APPGW.Name Kindly allow us few minutes. -ForegroundColor Cyan
Set-AzApplicationGateway -ApplicationGateway $APPGW
if($APPGW.ProvisioningState -eq "Failed")
{Write-Host Unable to update the status. Kindly contact Microsoft support}
}
else
{
if($APPGW.OperationalState -eq "Stopped")
{
Write-Host The Application Gateway $APPGW.Name is in STOP state -BackgroundColor Red -ForegroundColor White
$StartAppGw = Read-Host -Prompt "Would you like to START the Application Gateway? Y/N"
if($StartAppGw -eq "Y")
{
Write-Host Application Gateway $APPGW.Name is starting -ForegroundColor Green
Start-AzApplicationGateway -ApplicationGateway $APPGW
$APPGW = Get-AzApplicationGateway -Name $APPGWName -ResourceGroupName $RGName
Write-Host The Application Gateway $APPGW.Name has been started successully -ForegroundColor Green
}
else
{break}
}
else
{
Write-Host The Application Gateway $APPGW.Name is Running -ForegroundColor Green
$StopAppGw = Read-Host -Prompt "Would you like to STOP the Application Gateway? Y/N"
if($StopAppGw -eq "Y")
{
if(($APPGW.Sku.Tier -contains "Standard_v2") -or ($APPGW.Sku.Tier -contains "WAF_v2") )
{
Write-Host Application Gateway $APPGW.Name is of Version 2. The Public IP will remains the same. We have initiated the STOP operation -ForegroundColor Yellow
Stop-AzApplicationGateway -ApplicationGateway $APPGW
Write-Host The Application Gateway $APPGW.Name has been successully Stopped -ForegroundColor Green
}
else
{
Write-Host The Application Gateway $APPGW.Name is of Version 1. The STOP operation would release the current Public IP which would not be possible to Recover -ForegroundColor Yellow
Start-Sleep -Seconds 7
$StopAppGwConfirm = Read-Host -Prompt "Do you still wants to STOP the Application Gateway ? Y/N"
if($StopAppGwConfirm -eq "Y")
{
Write-Host Application Gateway $APPGW.Name will be stopped in few minutes -ForegroundColor Yellow
Stop-AzApplicationGateway -ApplicationGateway $APPGW
Write-Host The Application Gateway $APPGW.Name has been successully Stopped -ForegroundColor Green
}
else
{break}
}
}
else
{break}
}
}
}
$(login)