Skip to content

Instantly share code, notes, and snippets.

@nyanhp nyanhp/WhyIsntItEasier.ps1
Last active Jun 12, 2019

Embed
What would you like to do?
Enable Power BI IP ranges on Azure SQL Firewall
function Enable-AllTheRules
{
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[string]
$ResourceGroupName,
[Parameter(Mandatory)]
[string]
$ServerName
)
# From https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/limits-and-config#ip-addresses
$rules = @(
@{Asia = @('13.75.36.64', '13.75.36.79'), @( '13.67.8.240', '13.67.8.255'), @( '52.175.23.169'), @( '52.187.68.19') }
@{Australia = @('13.70.72.192', '13.70.72.207'), @( '13.72.243.10'), @( '13.77.50.240', '13.77.50.255'), @( '13.70.136.174') }
@{Brazil = @('191.233.203.192', '191.233.203.207'), @( '104.214.19.48', '104.214.19.63'), @( '13.65.86.57'), @( '104.41.59.51') }
@{Canada = @('13.71.170.208', '13.71.170.223'), @( '13.71.170.224', '13.71.170.239'), @( '52.237.24.126'), @( '40.69.106.240', '40.69.106.255'), @( '52.242.35.152') }
@{Europe = @('13.69.227.208', '13.69.227.223'), @( '52.178.150.68'), @( '13.69.64.208', '13.69.64.223'), @( '52.174.88.118'), @( '137.117.161.181') }
@{India = @('104.211.81.192', '104.211.81.207'), @( '52.172.211.12'), @( '40.78.194.240', '40.78.194.255'), @( '13.71.125.22'), @( '104.211.146.224', '104.211.146.239'), @( '104.211.189.218') }
@{Japan = @('13.78.108.0', '13.78.108.15'), @( '13.71.153.19'), @( '40.74.100.224', '40.74.100.239'), @( '104.215.61.248') }
@{SouthAmerica = @('191.233.203.192', '191.233.203.207'), @( '104.214.19.48', '104.214.19.63'), @( '13.65.86.57'), @( '104.41.59.51') }
@{UnitedKingdom = @('51.140.148.0', '51.140.148.15'), @( '51.140.80.51'), @( '51.140.211.0', '51.140.211.15'), @( '51.141.47.105') }
@{UnitedStates = @('13.89.171.80', '13.89.171.95'), @( '52.173.245.164'), @( '40.71.11.80', '40.71.11.95'), @( '40.71.249.205'), @( '40.70.146.208', '40.70.146.223'), @( '52.232.188.154'), @( '52.162.107.160', '52.162.107.175'), @( '52.162.242.161'), @( '40.112.243.160', '40.112.243.175'), @( '104.42.122.49') }
@{UnitedStatesEA = @('13.71.195.32', '13.71.195.47'), @( '52.161.102.22'), @( '13.66.140.128', '13.66.140.143'), @( '52.183.78.157') }
)
foreach ($rule in $rules)
{
$count = 0
[string]$rulename = $rule.Keys[0]
foreach ($iprange in $rule[$rulename])
{
$name = "$rulename$count"
$count++
if (Get-AzSqlServerFirewallRule @PSBoundParameters -FirewallRuleName $name) { continue }
New-AzSqlServerFirewallRule @PSBoundParameters -FirewallRuleName $($name) -StartIpAddress $($iprange[0]) -EndIpAddress $($iprange[-1])
}
}
}
Enable-AllTheRules -ResourceGroupName '<Your RG here>' -ServerName '<Your !!LOWERCASE!! servername here>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.