Files
Cloud-20Engineering/Powershell/Tools/WebApp Settings.ps1
2024-03-12 17:32:15 +01:00

71 lines
3.8 KiB
PowerShell

#Connect-AzAccount
# Set alias for az exe
Set-Alias -Name az -Value "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd"
Write-Host "======================================================================================================================================================================"
Write-Host "Updating webapp resource settings."
Write-Host "======================================================================================================================================================================"
$subscriptions = Get-AzSubscription | Where-Object State -eq "Enabled" | Where Name -NotLike "Visual Studio*" | Where Name -NotLike "*test*"
foreach ($subscription in $subscriptions)
{
Write-Host "----------------------------------------------------------------------------------------------------------------------------------------------------------------------"
Set-AzContext -SubscriptionId $subscription.Id
az account set --subscription $subscription.Id
Write-Host "----------------------------------------------------------------------------------------------------------------------------------------------------------------------"
$allResourceGroups = Get-AzResourceGroup
foreach ($group in $allResourceGroups) {
Write-Host "Resource group $($group.ResourceGroupName)"
$allWebApps = Get-AzWebApp -ResourceGroupName $group.ResourceGroupName
foreach ($webApp in $allWebApps) {
if (($webApp.SiteConfig.FtpsState -ne "Disabled") -and ($webApp.SiteConfig.FtpsState -ne "FtpsOnly")) {
Write-Host "Disable FTP $($webApp.Name)"
$x = Set-AzWebApp -Name $webApp.Name -ResourceGroupName $group.ResourceGroupName -FtpsState Disabled
}
if (($webApp.SiteConfig.PhpVersion -ne "off") -and ($webApp.SiteConfig.PhpVersion -ne "")) {
Write-Host "Disable PHP $($webApp.Name)"
$x = Set-AzWebApp -Name $webApp.Name -ResourceGroupName $group.ResourceGroupName -PhpVersion "off"
}
if ($webApp.SiteConfig.Http20Enabled -ne "TRUE") {
Write-Host "Enable HTTP/2 $($webApp.Name)"
az webapp config set -g $group.ResourceGroupName -n $webApp.Name --http20-enabled true | out-null
}
$allSlots = Get-AzWebAppSlot -Name $webApp.Name -ResourceGroupName $webApp.ResourceGroup
foreach ($slotTemp in $allSlots) {
[string] $slotName = $slotTemp.Name.Split("/")[1]
$slot = Get-AzWebAppSlot -Name $webApp.Name -ResourceGroupName $webApp.ResourceGroup -Slot $slotName
if (($slot.SiteConfig.FtpsState -ne "Disabled") -and ($webApp.SiteConfig.FtpsState -ne "FtpsOnly")) {
Write-Host "Disable FTP $($webApp.Name) - $($slotName)"
$y = Set-AzWebAppSlot -Name $webApp.Name -Slot $slotName -ResourceGroupName $group.ResourceGroupName -FtpsState Disabled
}
if (($slot.SiteConfig.PhpVersion -ne "") -and ($slot.SiteConfig.PhpVersion -ne "off")) {
Write-Host "Disable PHP $($webApp.Name) - $($slotName)"
$y = Set-AzWebAppSlot -Name $webApp.Name -Slot $slotName -ResourceGroupName $group.ResourceGroupName -PhpVersion "off"
}
if ($slot.SiteConfig.Http20Enabled -ne "TRUE") {
Write-Host "Enable HTTP/2 $($webApp.Name)"
az webapp config set -g $group.ResourceGroupName -n $webApp.Name --slot $slotName --http20-enabled true | out-null
}
}
}
}
}
Write-Host "======================================================================================================================================================================"
Write-Host "Done."