Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Resource Manager IP Security Restrictions using Powershell

I'm trying to use Powershell to set IP Security Restrictions. My syntax is not returning any errors, but settings are not changing. The "ipSecurityRestrictions" property is a hashtable.

$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

It's not a permissions issue, and there are no errors returned. To change a property that is not a hashtable, such as the phpVersion the following code is working fine:

$p.phpVersion = "7.0"

Anyone successfully set ipSecurityRestrictions using this method?

like image 249
Andy C Avatar asked Jan 05 '17 04:01

Andy C


Video Answer


1 Answers

ipSecurityRestrictions should be object array. Please have a try to change code as following. It works correctly for me.

$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

After that we can get the result from the resources azure (https://resources.azure.com).

enter image description here

We also can get powershell cmd from the resource azure.

enter image description here

like image 141
Tom Sun - MSFT Avatar answered Sep 22 '22 15:09

Tom Sun - MSFT