2
votes

I'm currently finishing up setting up our Azure network Security Groups and trying to find better ways to maintain our rules. I Have a script for azure powershell to create the security rules via CSV but wanted to export. When running the following command

Get-AzureNetworkSecurityGroup -Name "name" -Detailed | export-Csv c:/file.csv

I get the file but it doesn't give me the details to csv. It acts as if it ignores the -Detailed command. Anyone have the answer?

2

2 Answers

1
votes

If you are applying NSG on subnet level and NOT on VM level this will surely help you. Firstly find out the nsg name using-

$nsgName = (Get-AzureNetworkSecurityGroupForSubnet -VirtualNetworkName "MYNetwork" -SubnetName "MySubnet").Name

Now use the nsg name to find out the detailed NGS details-

Get-AzureNetworkSecurityGroup -Name $nsgName -Detailed | Export-csv -path "C:\nsgfile.csv"

Output of above command on console- enter image description here

[Updated answer]

1
votes

Try this :

(Get-AzureNetworkSecurityGroup -Name "name" -Detailed).Rules | Export-csv -path "C:\nsgfile.csv"