Forum Discussion
JosephDurnal1885
Mar 22, 2022Copper Contributor
Passing String to PSIpRule
I'm having an Azure PowerShell issue. I can copy and paste a string into a command, but as soon as I pass it as a variable, it doesn't work: String $rulestr @{IPAddress...
- Mar 25, 2022
I realized the problem was that I needed to supply an array variable instead of a string. Doing it with a regular array worked well until I added CIDR blocks to the list. I needed to define the array type first.
[Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule[]]$rulearr = @()This worked
[Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule[]]$rulearr = @(@{IPAddressOrRange="13.65.24.129";Action="allow"},@{IPAddressOrRange="13.66.138.94";Action="allow"},@{IPAddressOrRange="13.66.138.95";Action="allow"},@{IPAddressOrRange="13.66.141.224/29";Action="allow"}) Update-AzStorageAccountNetworkRuleSet -ResourceGroupName <RGName> -AccountName <StorageAccount> -IpRule $rulearrOf course, my next problem is that I need more than 200 IP addresses in the list, but that's not a PowerShell issue.
JosephDurnal1885
Mar 25, 2022Copper Contributor
I realized the problem was that I needed to supply an array variable instead of a string. Doing it with a regular array worked well until I added CIDR blocks to the list. I needed to define the array type first.
[Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule[]]$rulearr = @()
This worked
[Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule[]]$rulearr = @(@{IPAddressOrRange="13.65.24.129";Action="allow"},@{IPAddressOrRange="13.66.138.94";Action="allow"},@{IPAddressOrRange="13.66.138.95";Action="allow"},@{IPAddressOrRange="13.66.141.224/29";Action="allow"})
Update-AzStorageAccountNetworkRuleSet -ResourceGroupName <RGName> -AccountName <StorageAccount> -IpRule $rulearr
Of course, my next problem is that I need more than 200 IP addresses in the list, but that's not a PowerShell issue.