Passing String to PSIpRule

Occasional Contributor

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:












Command doesn't work





 Update-AzStorageAccountNetworkRuleSet -ResourceGroupName <RGName> -AccountName <SAName> -IpRule ($rulestr)





Update-AzStorageAccountNetworkRuleSet: Cannot bind parameter 'IPRule'. Cannot convert the "@{IPAddressOrRange="";Action="allow"},@{IPAddressOrRange="";Action="allow"},@{IPAddressOrRange="";Action="allow"}" value of type "System.String" to type "Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule".

Command works with exact copy/paste of string





Update-AzStorageAccountNetworkRuleSet -ResourceGroupName <RGName> -AccountName <SAName> -IpRule (@{IPAddressOrRange="";Action="allow"},@{IPAddressOrRange="";Action="allow"},@{IPAddressOrRange="";Action="allow"})





Bypass : AzureServices
DefaultAction : Deny
IpRules : [,...]
VirtualNetworkRules :
ResourceAccessRules :



1 Reply
best response confirmed by JosephDurnal1885 (Occasional 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="";Action="allow"},@{IPAddressOrRange="";Action="allow"},@{IPAddressOrRange="";Action="allow"},@{IPAddressOrRange="";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.