Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarangbk/19abf407f33803521bd223f5f6ef287e to your computer and use it in GitHub Desktop.
Save sarangbk/19abf407f33803521bd223f5f6ef287e to your computer and use it in GitHub Desktop.
Add-AzureRmAccount
Set-AzureRmContext -SubscriptionId '<Enter SubscriptionId here only if you have more than one subscriptions for the same email address/identity>'
$firewallRuleName = '<firewalll rule to remove/update if it already exists>'
$serverName = '<Database Server name for which rule is to be added>'
$resourceGroupName = '<Resource group of database server>'
$myIp = (Invoke-WebRequest ifconfig.me/ip).Content.Trim()
Write-Host 'Creating firewalll rule for ip',$myIp
Remove-AzureRmSqlServerFirewallRule -FirewallRuleName $firewallRuleName -ResourceGroupName $resourceGroupName -ServerName $serverName -WarningAction Continue -Force -ErrorAction Continue
New-AzureRmSqlServerFirewallRule -ResourceGroupName $resourceGroupName -ServerName $serverName -FirewallRuleName $firewallRuleName -StartIpAddress $myIp -EndIpAddress $myIp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment