forked from 12Knocksinna/Office365itpros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReporteDiscoveryCases.Ps1
74 lines (73 loc) · 3.34 KB
/
ReporteDiscoveryCases.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Report eDiscovery Cases
# https://github.com/12Knocksinna/Office365itpros/blob/master/ReporteDiscoveryCases.Ps1
# Used in Chapter 20 of Office 365 for IT Pros
$ClosedCases = 0 ;$ActiveHolds = 0
$Report = [System.Collections.Generic.List[Object]]::new()
Write-Host "Finding eDiscovery Cases"
$Cases = Get-ComplianceCase -ErrorAction SilentlyContinue
Write-Host $Cases.Count " cases found. Now extracting information."
ForEach ($Case in $Cases) {
Write-Host "Processing eDiscovery Case:" $Case.Name
$CaseMembers = (Get-ComplianceCaseMember -Case $Case.Name | Select Name, WindowsLiveId)
$Names = $Null
$First = $True
# Figure out display name for case managers - nicer than their email address
ForEach ($M in $CaseMembers) {
If ($First) {
$Names = $M.Name
$First = $False }
Else {
$Names = $Names, $M.Name -Join ", " } }
If ($Case.Status -eq "Closed") {
$ReportLine = [PSCustomObject]@{
Case = $Case.Name
Status = $Case.Status
Created = $Case.CreatedDateTime
ClosedBy = $Case.ClosedBy
Closed = $Case.ClosedDateTime
Members = $Names }
$Report.Add($ReportLine)
$ClosedCases++ }
ElseIf ($Case.Status = "Open") {
$HoldPolicies = (Get-CaseHoldPolicy -Case $Case.Name | % {Get-CaseHoldPolicy $_.Name -Case $_.CaseId -DistributionDetail})
ForEach ($Hold in $HoldPolicies) {
$HoldRule = Get-CaseHoldRule -Policy $Hold.Name
$ActiveHolds++
$i = 0 # Section of code to highlight inactive mailboxes that are under hold
$Mbxes = $Null
$CountMbx = 0
ForEach ($H in $Hold.ExchangeLocation) {
$Len = $Hold.ExchangeLocation[$i].DisplayName | Measure-Object -Character | Select -Expandproperty Characters
If ($Hold.ExchangeLocation[$i].DisplayName.Substring(0,1) -eq ".") {
$Mbx = ($Hold.ExchangeLocation[$i].DisplayName.Substring(1,$Len - 1)) + " (Inactive); "
$Mbxes = $Mbxes + $Mbx }
Else {
$Mbxes = $Mbxes + ($Hold.ExchangeLocation[$i].DisplayName) + "; " }
$CountMbx++
$i++ }
# Write out the report line
$ReportLine = [PSCustomObject]@{
Case = $Case.Name
Status = $Case.Status
Created = Get-Date ($Case.CreatedDateTime) -format g
ClosedBy = $Case.ClosedBy
Closed = Get-Date($Case.ClosedDateTime) -format g
Members = $Names
Hold = $Hold.Name
HoldEnabled = $Hold.Enabled
HoldCreatedby = $Hold.CreatedBy
HoldModifiedby = $Hold.LastModifiedBy
Mailboxes = $Mbxes
MailboxCount = $CountMbx
SPOSites = ($Hold.SharePointLocation.Name) -Join ","
Query = $HoldRule.ContentMatchQuery
HoldCreated = Get-Date($HoldRule.WhenCreatedUTC) -format g
HoldModifued = Get-Date($HoldRule.WhenChangedUTC) -format g }
$Report.Add($ReportLine)
}
}}
Write-Host "EDiscovery Cases found: " $Cases.Count
Write-Host "Active Cases: " ($Cases.Count - $ClosedCases)
Write-Host "Closed Cases: " $ClosedCases
Write-Host "Active Holds: " $ActiveHolds
$Report | Sort Status, Case | Format-Table Case, Status, Created, HoldCreated