2017-01-05 22 views
5

Tôi đang cố gắng sử dụng Powershell để đặt Giới hạn bảo mật IP. Cú pháp của tôi không trả về bất kỳ lỗi nào, nhưng cài đặt không thay đổi. Thuộc tính "ipSecurityRestrictions" là một hashtable.Hạn chế bảo mật IP của Trình quản lý tài nguyên Azure bằng Powershell

$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 

Đây không phải là vấn đề về quyền và không có lỗi nào được trả về. Để thay đổi thuộc tính đó không phải là một Hashtable, chẳng hạn như phpVersion đoạn mã sau đang làm việc tốt:

$p.phpVersion = "7.0" 

Bất cứ ai cũng thiết lập thành công ipSecurityRestrictions sử dụng phương pháp này?

+0

Nếu hữu ích, bạn có thể giúp đánh dấu câu trả lời để giúp nhiều cộng đồng hơn không? –

Trả lời

4

ipSecurityRestrictions phải là mảng đối tượng. Vui lòng thử thay đổi mã như sau. Nó hoạt động chính xác cho tôi.

$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

Sau đó chúng ta có thể nhận được kết quả từ các nguồn lực Azure (https://resources.azure.com).

enter image description here

Chúng tôi cũng có thể nhận được PowerShell cmd từ xanh tài nguyên.

enter image description here

+0

Bạn là huyền thoại! Cảm ơn bạn - hoạt động hoàn hảo :) –

Các vấn đề liên quan