Steps:
- Increase Exchange MessageTrackingLogs from the default of 30 days (1Gb) to 90 days (3Gb)
- Export list of ALL DLs
- Export list of ALL active DLs based off Exchange Tracking Logs
- Compare the results and output the inactive DLs
- Hide all unused DLs from the GAL
- Delete all unused DLs from Exchange
- Note these are server specific commands and I need to do this on all hub transport servers
- Increasing the log will not remove the original logs
- We will have to wait 2 months after setting these logs up
Configure Message Tracking (http://technet.microsoft.com/en-us/library/aa997984.aspx)
1. Configuring Exchange MessageTrackingLogs settings
Get-TransportServer | fl name,*messagetracking* Get-TransportServer | ` Set-TransportServer -MessageTrackingLogMaxDirectorySize 3072MB ` -MessageTrackingLogMaxAge 180.00:00:00 Get-TransportServer | fl name,*messagetracking*2. Export list of ALL DLs
Get-DistributionGroup -ResultSize Unlimited | ` Select-Object PrimarySMTPAddress | ` Sort-Object PrimarySMTPAddress | ` Export-CSV DL-ALL_Present_Tense.csv -notype3. Export list of ALL active DLs based off Exchange Tracking Logs
Get-TransportServer | `
Get-MessageTrackingLog -EventId Expand -ResultSize Unlimited | `
Sort-Object RelatedRecipientAddress | `
Group-Object RelatedRecipientAddress | `
Sort-Object Name | `
Select-Object @{label="PrimarySmtpAddress"; `
expression={$_.Name}}, Count | `
Export-CSV DL-ACTIVE_Historical.csv –notype
4. Compare the results and output the inactive DLs$file1 = Import-CSV -Path "DL-ALL_Present_Tense.csv"
$file2 = Import-CSV -Path "DL-ACTIVE_Historical.csv"
Compare-Object $file1 $file2 -syncWindow 1000 `
-Property PrimarySmtpAddress -PassThru | `
Where-Object{$_.SideIndicator -eq '<='} | `
Select-Object -Property PrimarySmtpAddress | `
Export-Csv DL-EXISTING_DLs_Inactive_last_180_days.csv -NoType
5. Compare the results and output the "non-existing" active DLs (documentation purposes only)
$file1 = Import-CSV -Path "DL-ALL_Present_Tense.csv"
$file2 = Import-CSV -Path "DL-ACTIVE_Historical.csv"
Compare-Object $file1 $file2 -syncWindow 1000 `
-Property PrimarySmtpAddress -PassThru | `
Where-Object{$_.SideIndicator -eq '=>'} | `
Select-Object -Property PrimarySmtpAddress | `
Export-Csv DL-NONEXISTING_DLs_Inactive_last_180_days.csv -NoType
6a. Hide all unused DLs from the Global Address List
$a = Get-Date
$notes = "$a - Hidden from address list due to inactive use."
$inactiveDL = Import-CSV -Path "DL-EXISTING_DLs_Inactive_for_180_days.csv"
foreach ($DL in $inactiveDL)
{
Set-Group -identity $DL.PrimarySmtpAddress -notes $notes
Set-DistributionGroup -identity $DL.PrimarySmtpAddress `
-HiddenFromAddressListsEnabled $true
}
6b. Delete all unused DLs from the Global Address List
$a = Get-Date
$notes = "$a - No longer mail enabled due to inactive use."
$inactiveDL = Import-CSV -Path "DL-EXISTING_DLs_Inactive_for_180_days.csv"
foreach ($DL in $inactiveDL)
{
Set-Group -identity $_.PrimarySmtpAddress -notes $notes
Disable-DistributionGroup -identity $_.PrimarySmtpAddress -Confirm $false
}
No comments:
Post a Comment