Created
January 14, 2016 23:06
-
-
Save jeffpatton1971/ae0b3bcd849e0638a871 to your computer and use it in GitHub Desktop.
A script that will enable diagnostics on network security groups. This will add the logs to a specific storage account.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param | |
( | |
[string]$StorageAccountName, | |
[string]$StorageAccountResourceGroup | |
) | |
try | |
{ | |
$ErrorActionPreference = "Stop" | |
$Error.Clear() | |
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $StorageAccountResourceGroup -Name $StorageAccountName | |
$NetworkSecurityGroups = Get-AzureRmNetworkSecurityGroup | |
foreach ($NetworkSecurityGroup in $NetworkSecurityGroups) | |
{ | |
$DiagnosticSettings = Get-AzureRmDiagnosticSetting -ResourceId $NetworkSecurityGroup.Id | |
if ($DiagnosticSettings.StorageAccountId -eq $null) | |
{ | |
if($NetworkSecurityGroup.ResourceGroupName.Contains($StorageAccountResourceGroup)) | |
{ | |
Set-AzureRmDiagnosticSetting -ResourceId $NetworkSecurityGroup.Id -StorageAccountId $StorageAccount.Id -Enabled $true -Categories 'NetworkSecurityGroupEvent','NetworkSecurityGroupRuleCounter' | |
} | |
} | |
} | |
} | |
catch | |
{ | |
Write-Output $Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment