Skip to content

Commit

Permalink
Merge pull request #8 from scott1138/1.2.0
Browse files Browse the repository at this point in the history
update to v 1.2.0
  • Loading branch information
scott1138 authored Jul 17, 2020
2 parents 9d43dbe + dd5366f commit 8207694
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
5 changes: 3 additions & 2 deletions PS-Tools/PS-Tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PS-Tools.psm1'

# Version number of this module.
ModuleVersion = '1.1.0'
ModuleVersion = '1.2.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -93,7 +93,8 @@ FunctionsToExport = @(
'Get-TimeStamp',
'Set-ResourceGroupTags',
'Write-InformationPlus',
'Set-PSToolsConfig'
'Set-PSToolsConfig',
'Remove-AzAppGwConfig'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
111 changes: 111 additions & 0 deletions PS-Tools/Public/Remove-AzAppGwConfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
function Remove-AzAppGwConfig {

[CmdletBinding(SupportsShouldProcess=$True)]

param (

[Parameter(Mandatory = $true)]
[string]
$RGName,

[Parameter(Mandatory = $true)]
[string]
$AppGwName

)

begin {}

process {
$WarningPreference = 'SilentlyContinue'

# Get App Gateway
Write-InformationPlus -Message "Getting Application Gateway $AppGWName..." -NoNewLine
try {
$AppGW = Get-AzApplicationGateway -ResourceGroupName $RGName -Name $AppGWName
Write-InformationPlus -Message "Done!" -ForegroundColor Green
}
catch {
Write-InformationPlus "Error!" -ForegroundColor Red
Format-Error -e $_ -Message 'Failed to get Application Gateway'
}

$Changes = @()

Write-InformationPlus -Message "Processing Request Routing Rules..."
$Items = Get-AzApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGW
foreach ($Item in $Items) {
$Response = Get-Input -Prompt "Do you want to remove $($Item.Name)?" -Default 'N' -ValidResponses @('Y','N')
if ($Response -eq 'Y') {
Remove-AzApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGW -Name $Item.Name | Out-Null
$Changes += $Item.Name
}
}

Write-InformationPlus -Message "Processing Redirect Configurations..."
$Items = Get-AzApplicationGatewayRedirectConfiguration -ApplicationGateway $AppGW
foreach ($Item in $Items) {
$Response = Get-Input -Prompt "Do you want to remove $($Item.Name)?" -Default 'N' -ValidResponses @('Y','N')
if ($Response -eq 'Y') {
Remove-AzApplicationGatewayRedirectConfiguration -ApplicationGateway $AppGW -Name $Item.Name | Out-Null
$Changes += $Item.Name
}
}

Write-InformationPlus -Message "Processing HTTP Listeners..."
$Items = Get-AzApplicationGatewayHttpListener -ApplicationGateway $AppGW
foreach ($Item in $Items) {
$Response = Get-Input -Prompt "Do you want to remove $($Item.Name)?" -Default 'N' -ValidResponses @('Y','N')
if ($Response -eq 'Y') {
Remove-AzApplicationGatewayHttpListener -ApplicationGateway $AppGW -Name $Item.Name | Out-Null
$Changes += $Item.Name
}
}

Write-InformationPlus -Message "Processing Backend HTTP Settings..."
$Items = Get-AzApplicationGatewayBackendHttpSetting -ApplicationGateway $AppGW
foreach ($Item in $Items) {
$Response = Get-Input -Prompt "Do you want to remove $($Item.Name)?" -Default 'N' -ValidResponses @('Y','N')
if ($Response -eq 'Y') {
Remove-AzApplicationGatewayBackendHttpSetting -ApplicationGateway $AppGW -Name $Item.Name | Out-Null
$Changes += $Item.Name
}
}

Write-InformationPlus -Message "Processing Custom Health Probes..."
$Items = Get-AzApplicationGatewayProbeConfig -ApplicationGateway $AppGW
foreach ($Item in $Items) {
$Response = Get-Input -Prompt "Do you want to remove $($Item.Name)?" -Default 'N' -ValidResponses @('Y','N')
if ($Response -eq 'Y') {
Remove-AzApplicationGatewayProbeConfig -ApplicationGateway $AppGW -Name $Item.Name | Out-Null
$Changes += $Item.Name
}
}

# Confirm Changes and Execute
Write-InformationPlus -Message "The following items will be removed!!!!" -ForegroundColor Yellow
Write-InformationPlus -Message ($Changes -join "`n")
$Response = Get-Input -Prompt "Do you want to continue (YES/NO)?" -Default 'NO' -ValidResponses @('YES','NO')
if ($Response -eq 'YES') {
Write-InformationPlus "`nCommitting Application Gateway changes..." -ForegroundColor Green
try {
$StartTime = Get-Date
Set-AzApplicationGateway -ApplicationGateway $AppGW | Out-Null
$EndTime = Get-Date
}
catch {
Export-Clixml -Path "$Env:TEMP\appgw.xml" -InputObject $AppGw -Force
Format-Error -e $_ -Message "Failed to commit Application Gateway changes. Check AppGw object at $Env:TEMP\appgw.xml."
}

Write-InformationPlus "Changes committed successfully!" -ForegroundColor Green
$ExecTime = New-TimeSpan -Start $StartTime -End $EndTime
$ExecMin = $ExecTime.Minutes
$ExecSec = $ExecTime.Seconds
Write-InformationPlus "Total Execution Time: $ExecMin minutes $ExecSec seconds."
}

}

end {}
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ PS-Tools is a collection of tools to simplify the administrative processes.
* [Pending Improvements](#Pending-Improvements)

## Change Log
* v1.2.0 - 2020-7-17
* New Cmdlets
* Set-PSToolsConfig
* Remove-AzAppGwConfig
* Can remove multiple configuration items during a single transaction.
* Currently text based can can remove routing rules, redirect configurations, http settings, probes, and listeners.
* Has a confirmation and support -whatif but be VERY careful!
* v1.1.0 - 2020-7-13
* New Cmdlets
* Set-PSToolsConfig
Expand Down

0 comments on commit 8207694

Please sign in to comment.