I am trying to use powershell to export all Network Security Group (NSG) rules across all subscriptions in Azure.
$sub = Get-AzSubscription
$sub | foreach-object {
$null = $PSItem | Select-AzSubscription
$null = Get-AzNetworkSecurityGroup -OutVariable +nsg
foreach ($obj in $nsg)
{
$obj.SecurityRules | Select-Object -OutVariable +rules @{ n = 'NSG Name'; e = {$obj.Name}},
@{ n = 'ResourceGroupName'; e = {$obj.ResourceGroupName}},
*
}
}
$rules | export-csv C:\Users\ABC\Desktop\NSG.csv
However, the exported csv files has many field with "System.Collections.Generic.List`1[System.String]", even though I can see the for loop is running fine and all the data is generated.
I am very new to powershell so any help on this would be much appreciated.