I am using PowerShell to create Azure NSGs which will use input from a .csv file with security rules. I am using the script below.
$NSG = Get-AzureRmNetworkSecurityGroup -Name test -ResourceGroupName RG-VM-QTY
foreach($rule in import-csv "SystemPath\inputfile.csv")
{
$NSG | Add-AzureRmNetworkSecurityRuleConfig -Name $rule.name -Access Allow -Protocol $rule.protocol -Direction $rule.direction -Priority $rule.priority
-SourceAddressPrefix $rule.source -SourcePortRange *
-DestinationAddressPrefix $rule.destination -DestinationPortRange $rule.port
}
$NSG | Set-AzureRmNetworkSecurityGroup
Wanted to check if there is a way to restrict adding a particular IP lets say 127.0.0.1 to be added as source or destination in any of the rules. Any check that I can put to avoid creating the NSG altogether if the IP 127.0.0.1 is present in the .csv?
Thanks in advance guys.! Cheers.