Reputation: 1433
Issue : When i create the new sql server and DB. My next task is to connect with DB but it breaks due Client IP not added in the firewall of sql server. I don't want to add it manually. Is there any way to set it using Powershell? and it should be the exact same IP which i am able to see inside azure sql server Firewalls and virtual networks.
Workaround Currently i added the IP range from 0.0.0.0 to 255.255.255.255 using azure sql task but it is not the right way to do it.
exec sp_set_firewall_rule N'AllowAzure', '0.0.0.0', '255.255.255.255';
Upvotes: 2
Views: 984
Reputation: 59031
Yes, you can use the Set-AzureRmSqlServerFirewallRule
cmdlet.
To retrieve the current IP I use ipify.org. Example:
$clientIp = Invoke-WebRequest 'https://api.ipify.org' | Select-Object -ExpandProperty Content
Set-AzureRmSqlServerFirewallRule `
-ResourceGroupName "myrg" `
-ServerName "myserver" `
-FirewallRuleName "myrulename" `
-StartIpAddress $clientIp `
-EndIpAddress $clientIp
Upvotes: 2