forked from 12Knocksinna/Office365itpros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindInactiveDLs.PS1
31 lines (28 loc) · 1.22 KB
/
FindInactiveDLs.PS1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# FindInactiveDls
# Find inactive distribution lists based on the message trace informnation, which means we can only go back 7 days...
#
$EndDate = Get-Date
$StartDate = $EndDate.AddDays(-10)
$Messages = $null
$Page = 1
Write-Host "Collecting message trace data for the last 10 days"
Do
{
$CurrMessages = (Get-MessageTrace -Status Expanded -PageSize 5000 -Page $Page -StartDate $StartDate -EndDate $EndDate | Select Received, RecipientAddress)
$Page++
$Messages += $CurrMessages
}
Until ($CurrMessages -eq $Null)
$MessageTable = @{}
$Messagetable = ($Messages | Sort RecipientAddress -Unique | Select RecipientAddress, Received)
$DLs = Get-DistributionGroup -ResultSize Unlimited
Write-Host "Processing" $DLs.Count "distribution lists..."
$Results = ForEach ($DL in $DLs) {
If ($MessageTable -Match $DL.PrimarySMTPAddress) {
[pscustomobject]@{Name = $DL.DisplayName ; Active = "Yes"}
Write-Host $DL.DisplayName "is active" -Foregroundcolor Yellow }
Else {
[pscustomobject]@{Name = $DL.DisplayName ; Active = "No"}
Write-Host $DL.DisplayName "inactive" -Foregroundcolor Red }
}
$Results | Export-CSV c:\Temp\ListofDLs.csv -NoTypeInformation