powershell - 使用 Powershell 的 Azure 资源管理器 IP 安全限制

标签 powershell azure azure-resource-manager

我正在尝试使用 Powershell 设置 IP 安全限制。我的语法没有返回任何错误,但设置没有改变。 “ipSecurityRestrictions”属性是一个哈希表。

$r = Get-AzureRmResource -ResourceGroupName *resource-group-name* -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01
$p = $r.Properties
$p.ipSecurityRestrictions = @{ ipAddress = "0.0.0.0"; subnetMask = "0.0.0.0" }
Set-AzureRmResource -ResourceGroupName *resource-group-name* -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01 -PropertyObject $p

这不是权限问题,并且没有返回任何错误。要更改不是哈希表的属性,例如 phpVersion,以下代码可以正常工作:

$p.phpVersion = "7.0"

有人使用此方法成功设置 ipSecurityRestrictions 吗?

最佳答案

ipSecurityRestrictions 应该是对象数组。请尝试更改以下代码。它对我来说工作正常。

$r = Get-AzureRmResource -ResourceGroupName "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01

$p = $r.Properties
$p.ipSecurityRestrictions = @()
$restriction = @{}
$restriction.Add("ipAddress","0.0.0.0")
$restriction.Add("subnetMask","0.0.0.0")
$p.ipSecurityRestrictions+= $restriction

Set-AzureRmResource -ResourceGroupName  "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01 -PropertyObject $p

enter image description here

之后我们可以从azure资源中获取结果 (https://resources.azure.com)。

enter image description here

我们还可以从资源 azure 获取 powershell cmd。

enter image description here

关于powershell - 使用 Powershell 的 Azure 资源管理器 IP 安全限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41477518/

相关文章:

string - 如何将多个字符串参数传递给 PowerShell 脚本?

azure - 是否可以通过变量访问Azure Pipelines中任务中的测试执行结果?

azure - 将存储添加到 Azure 资源管理器

azure - 通过 Microsoft Graph 数据连接或内容搜索或其他方式进行就地存档访问

azure - ARM模板: how to read output result in array format

azure - 如何使用 ARM 模板中没有值的 secret 来管理 Azure Key Vault?

powershell - Get-ChildItem -Exclude 参数如何工作?

azure - Azure Devops 中的 Invoke-Restmethod powershell - 奇怪的 powershell 错误

c# - 如何清除服务总线主题订阅的消息

azure - 如何将网站添加到 Windows Azure 中的虚拟网络?