Skip to content

Instantly share code, notes, and snippets.

@averkinderen
Created May 18, 2017 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averkinderen/6002c7658c5a9d47cb92888dc31c167a to your computer and use it in GitHub Desktop.
Save averkinderen/6002c7658c5a9d47cb92888dc31c167a to your computer and use it in GitHub Desktop.
#variables
$ResourgeGroupName = Read-Host "Please provide name of ResourgeGroup that will be used for saving the NSG logs"
$StorageAccountLogs = Read-Host "Please provide name of Storage Account that will be used for saving the NSG logs"
#Login to the Azure Resource Management Account
Login-AzureRmAccount
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.Insights
#region Get Azure Subscriptions
$subscriptions = Get-AzureRmSubscription
$menu = @{}
for ($i = 1;$i -le $subscriptions.count; $i++)
{
Write-Host -Object "$i. $($subscriptions[$i-1].Name)"
$menu.Add($i,($subscriptions[$i-1].Id))
}
[int]$ans = Read-Host -Prompt 'Enter selection'
$subscriptionID = $menu.Item($ans)
$subscription = Get-AzureRmSubscription -SubscriptionId $subscriptionID
Set-AzureRmContext -SubscriptionName $subscription.Name
#endregion
$subId = (Get-AzureRmContext).Subscription.Id
$subName = (Get-AzureRmContext).Subscription.Name
#regionGet Azure details details
$NW = Get-AzurermNetworkWatcher
#endregion
Foreach($NW in $NWs){
$NWlocation = $NW.location
write-host "Looping trough $NWlocation" -ForegroundColor Yellow
#region Enable NSG Flow Logs
$nsgs = Get-AzureRmNetworkSecurityGroup | Where-Object {$_.Location -eq $NWlocation}
Foreach($nsg in $nsgs)
{
Get-AzureRmNetworkWatcherFlowLogStatus -NetworkWatcher $NW -TargetResourceId $nsg.Id
Set-AzureRmNetworkWatcherConfigFlowLog -NetworkWatcher $NW -TargetResourceId $nsg.Id -StorageAccountId $storageAccount.Id -EnableFlowLog $false
write-host "Diagnostics disabled for $nsg.Name " -BackgroundColor Green
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment