如何通过PowerShell(Azure CLI)启用“允许Azure服务和资源访问此服务器”?

8
使用 az sql server create 创建新的 Azure SQL 服务器后,如何通过 PowerShell(Azure CLI)启用以下选项?

enter image description here

5个回答

14

如果你搜索 "azure sql firewall allow azure services",就可以在 Azure SQL 的文档中找到相关内容。但这里是你需要做的——创建一个起始地址和终止地址都为 0.0.0.0 的规则,就像这样:

az sql server firewall-rule create --resource-group <resource group name> --server <azure sql name> -n <any name> --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0

这似乎启用了该选项。谢谢! - Mason
2
它在API文档中:https://learn.microsoft.com/zh-cn/rest/api/sql/firewallrules/createorupdate - Isaac Rosado

3
为了进一步解释Scott的回答,使用Azure PowerShell模块实现这个功能的等效方法如下:
New-AzSqlServerFirewallRule -FirewallRuleName <fw-rule-name> -StartIpAddress '0.0.0.0' -EndIpAddress '0.0.0.0' -ServerName <sql-server-name> -ResourceGroupName <resource-group-name>

1
当您将“拒绝公共访问”设置为“是”时,您知道该怎么办吗?然后您无法配置防火墙规则。 - Piotr Perak

2

我在这里做出了一点小贡献。

以下的az命令与相应的组和sqlservername设置"允许Azure服务和资源访问此服务器"为是。

az sql server firewall-rule create -g -s -n AllowAllWindowsAzureIps --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0


1

只需添加一个具有特定名称(AllowAllWindowsAzureIps)的新规则;

New-AzSqlServerFirewallRule -ResourceGroupName <resourceGroup> -ServerName <serverName> -FirewallRuleName "AllowAllWindowsAzureIps" -StartIpAddress "0.0.0.0" -EndIpAddress "0.0.0.0"

0

刚刚看到这个,我相信现在可以通过以下脚本实现...

New-AzSqlServerFirewallRule -ResourceGroupName <ResourceGroup> -ServerName <SQLServerName> -AllowAllAzureIPs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接