I have a PowerShell script that whitelists IPs to Azure Web Apps based on IPs in a file:
$ResourceGroupName = 'RG'
$WebAppName = 'WebApp'
$WhitelistFilePath = 'C:\IPs.txt'
$IPs = Get-Content $WhitelistFilePath
$name = 600
$priority = 600
foreach($IP in $IPs)
{
Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $WebAppName -Name "IP-$name" -Priority "$priority" -Action Allow -IpAddress "$IP/24"
$name ++
$priority ++
}
The script works fine with simple list of IPs. C:\IPs.txt:
10.0.0.0
100.0.0.0
Getting:
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name IP-600 -Priority 600 -Action Allow -IpAddress 10.0.0.0/24
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name IP-601 -Priority 601 -Action Allow -IpAddress 100.0.0.0/24
However, I'd also like to add names for those IPs, so C:\IPs.txt looks like this:
Ben's IP
10.0.0.0
John's IP
100.0.0.0
How can I edit my script so I receive:
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name "Ben's IP" -Priority 600 -Action Allow -IpAddress 10.0.0.0/24
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name "John's IP" -Priority 601 -Action Allow -IpAddress 100.0.0.0/24
Instead of what I'm getting now:
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name IP-600 -Priority 600 -Action Allow -IpAddress Ben's IP/24
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name IP-601 -Priority 601 -Action Allow -IpAddress 10.0.0.0/24
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name IP-602 -Priority 602 -Action Allow -IpAddress John's IP/24
Add-AzWebAppAccessRestrictionRule -ResourceGroupName RG -WebAppName WebApp -Name IP-603 -Priority 603 -Action Allow -IpAddress 100.0.0.0/24