Create Azure Network Security Group (NSG) from CSV inputs

A simple PowerShell script that can be used to create Azure Resource Manager Network Security Groups (NSG) from CSV input files.It accepts 2 input CSV files, the purpose of having 2 files is to have a set of Default rules that can apply to all NSGs, and then a custom set of rules

1,028 times
Add to favorites
Windows Azure
E-mail Twitter Digg Facebook
Sign in to ask a question

  • I've been unable to resolve this error...Please help!
    1 Posts | Last post July 19, 2018
    • 62. New-AzureRmNetworkSecurityGroup -Name $nsgName -ResourceGroupName $resourceGroup -Location $location -SecurityRules $rulesArray
      PS C:\Script> c:\script\Create-AzureRmNsg17.ps1 -nsgName nsg1 -resourceGroup rg1 -location eastus -defaultCsv defaultRules.csv -customCsv customRules.csv
      ResourceGroupName : rg1
      Location          : eastus
      ProvisioningState : Succeeded
      Tags              : 
      ResourceId        : /subscriptions/.../resourceGroups/rg1
      WARNING: The output object type of this cmdlet will be modified in a future release.
      New-AzureRmNetworkSecurityGroup : Cannot parse the request.
      StatusCode: 400
      ReasonPhrase: Bad Request
      OperationID : '...'
      At C:\script\Create-AzureRmNsg17.ps1:62 char:1
      + New-AzureRmNetworkSecurityGroup -Name $nsgName -ResourceGroupName $re ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : CloseError: (:) [New-AzureRmNetworkSecurityGroup], NetworkCloudException
          + FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.NewAzureNetworkSecurityGroupCommand
      PS C:\Script> 
  • Need similiar script for Classic Deployment
    2 Posts | Last post May 31, 2016
    • Hi MIchael, 
      Our current deployment in Azure is still in Classic Mode. Please could you share a similar script. Also let me know what are the requirement for powershell to read and pick up values from CSV ??
    • Classic/ASM you have to add each rule in one at a time.
      Something like:
       $rules = Import-Csv "c:\scripts\nsg.csv"
       foreach ($rule in $rules)
          Get-AzureNetworkSecurityGroup -Name 'name'| Set-AzureNetworkSecurityRule -Name $rule.Name -Type $rule.type -Priority $rule.priority -Action $rule.action -SourceAddressPrefix $rule.source -SourcePortRange $rule.sourceport -DestinationAddressPrefix $rule.destination -DestinationPortRange $rule.destport -Protocol $rule.protocol