SOLVED

Passing String to PSIpRule

Copper 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:

String

 

 

 

 

$rulestr

 

 

 

 

@{IPAddressOrRange="13.65.24.129";Action="allow"},@{IPAddressOrRange="13.66.138.94";Action="allow"},@{IPAddressOrRange="13.66.138.95";Action="allow"}

Command doesn't work

 

 

 

 

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

 

 

 

 

Update-AzStorageAccountNetworkRuleSet: Cannot bind parameter 'IPRule'. Cannot convert the "@{IPAddressOrRange="13.65.24.129";Action="allow"},@{IPAddressOrRange="13.66.138.94";Action="allow"},@{IPAddressOrRange="13.66.138.95";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="13.65.24.129";Action="allow"},@{IPAddressOrRange="13.66.138.94";Action="allow"},@{IPAddressOrRange="13.66.138.95";Action="allow"})

 

 

 

 

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

 

 

1 Reply
best response confirmed by JosephDurnal1885 (Copper Contributor)
Solution

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.

1 best response

Accepted Solutions
best response confirmed by JosephDurnal1885 (Copper Contributor)
Solution

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.

View solution in original post