Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PatrickKalkman/5550afb949619f5d72135d6327ea8d74 to your computer and use it in GitHub Desktop.
Save PatrickKalkman/5550afb949619f5d72135d6327ea8d74 to your computer and use it in GitHub Desktop.
function Add-AccessRestrictionToAppService([string] $ResourceGroupName, [string] $Name, [string] $IpFilterRuleName, [string] $IpAddress, [string] $Priority)
{
Write-Information "Adding rule $IpFilterRuleName to allow api management service with ip $IpAddress and $Priority access to $Name"
Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Name $IpFilterRuleName -Priority $Priority -Action Allow -IpAddress $IpAddress
Update-AzWebAppAccessRestrictionConfig -Name $appService.Name -ResourceGroupName $ResourceGroupName -ScmSiteUseMainSiteRestrictionConfig
# Also add the access restriction to the staging slots
$allSlots = Get-AzWebAppSlot -ResourceGroupName $ResourceGroupName -Name $Name
Foreach ($slot in $allSlots)
{
$slotName = Get-SlotName -SlotName $slot.Name -AppServiceName $Name
Write-Information "Adding rule $IpFilterRuleName to allow api management service with ip $IpAddress and priority $Priority access to $Name slot $slotName"
Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Slot $slotName -Name $IpFilterRuleName -Priority $Priority -Action Allow -IpAddress $IpAddress
Update-AzWebAppAccessRestrictionConfig -ResourceGroupName $ResourceGroupName -Name $Name -Slot $slotName -ScmSiteUseMainSiteRestrictionConfig
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment