-
Notifications
You must be signed in to change notification settings - Fork 0
/
Update-AzStorageAccount-ipRange.ps1
38 lines (28 loc) · 1.21 KB
/
Update-AzStorageAccount-ipRange.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function Update-AzStorageAccount-ipRange {
[cmdletbinding()]
## Define parameters
Param (
[string]$ipRanges
)
$subs = @( "subid"
)
foreach ($sub in $subs) {
$subName = (Get-AzSubscription -SubscriptionId $sub).Name
Write-Output "Setting context to $subName"
Set-AzContext -SubscriptionId $sub
## Get all Storage Accounts within a subscription
$storageAccounts = Get-AzStorageAccount
Write-Output "Starting Storage Accounts"
foreach ($storageAccount in $storageAccounts) {
$networkRuleStatus = $storageAccount.NetworkRuleSet.DefaultAction
if ($networkRuleStatus -ne "Allow") {
Write-Output "Adding IP ranges to $($storageAccount.StorageAccountName)."
Add-AzStorageAccountNetworkRule -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.StorageAccountName -IPAddressOrRange $ipRanges
Write-Output "$($storageAccount.StorageAccountName) is complete."
}
else {
Write-Output "The Network Ruleset is set to Allowed on $($storageAccount.StorageAccountName)."
}
}
}
}