-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet-Office365UnifiedAuditLogs.ps1
142 lines (135 loc) · 3.69 KB
/
Get-Office365UnifiedAuditLogs.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Setup
# https://outlook.office365.com/ecp > Hybrid > "The Exchange Online PowerShell Module..." > Configure > Install
#Uninstall-Module ExchangeOnlineManagement
#Install-Module ExchangeOnlineManagement
# Single Factor
#$UserCredential = Get-Credential
#Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true
# MFA
Import-Module ExchangeOnlineManagement
Connect-EXOPSSession -UserPrincipalName [email protected]
$OutDir = "C:\Logs"
$StartDate = (Get-Date).AddDays(-365)
$EndDate = get-date
# Set the user you wish to gather data for
$userSMTP = "[email protected]"
If (!(Test-Path $OutDir))
{
New-Item -ItemType Directory -Path $OutDir -ErrorAction SilentlyContinue | Out-Null
}
# Note: Splitting out recordtypes is one of many workarounds to the 5000 result limit.
$RecordTypes = (
"AeD",
"AipDiscover",
"AipFileDeleted",
"AipHeartBeat",
"AipProtectionAction",
"AipSensitivityLabelAction",
"AirAdminActionInvestigation",
"AirInvestigation",
"AirManualInvestigation",
"ApplicationAudit",
"AttackSim",
"AzureActiveDirectory",
"AzureActiveDirectoryAccountLogon",
"AzureActiveDirectoryStsLogon",
"CRM",
"Campaign",
"ComplianceDLPExchange",
"ComplianceDLPExchangeClassification",
"ComplianceDLPSharePoint",
"ComplianceDLPSharePointClassification",
"ComplianceSupervisionExchange",
"CortanaBriefing",
"CustomerKeyServiceEncryption",
"DLPEndpoint",
"DataCenterSecurityCmdlet",
"DataGovernance",
"DataInsightsRestApiAudit",
"Discovery",
"ExchangeAdmin",
"ExchangeAggregatedOperation",
"ExchangeItem",
"ExchangeItemAggregated",
"ExchangeItemGroup",
"ExchangeSearch",
"HRSignal",
"HygieneEvent",
"InformationBarrierPolicyApplication",
"InformationWorkerProtection",
"Kaizala",
"LabelContentExplorer",
"MCASAlerts",
"MDATPAudit",
"MIPLabel",
"MS365DCustomDetection",
"MSDEGeneralSettings",
"MSDEIndicatorsSettings",
"MSDEResponseActions",
"MSDERolesSettings",
"MSTIC",
"MailSubmission",
"MicrosoftFlow",
"MicrosoftForms",
"MicrosoftStream",
"MicrosoftTeams",
"MicrosoftTeamsAdmin",
"MicrosoftTeamsAnalytics",
"MicrosoftTeamsDevice",
"MicrosoftTeamsShifts",
"MipAutoLabelExchangeItem",
"MipAutoLabelSharePointItem",
"MipAutoLabelSharePointPolicyLocation",
"MipExactDataMatch",
"MyAnalyticsSettings",
"OfficeNative",
"OnPremisesFileShareScannerDlp",
"OnPremisesSharePointScannerDlp",
"OneDrive",
"PhysicalBadgingSignal",
"PowerAppsApp",
"PowerAppsPlan",
"PowerBIAudit",
"PrivacyInsights",
"Project",
"Quarantine",
"Search",
"SecurityComplianceAlerts",
"SecurityComplianceCenterEOPCmdlet",
"SecurityComplianceInsights",
"SecurityComplianceRBAC",
"SecurityComplianceUserChange",
"SensitivityLabelAction",
"SensitivityLabelPolicyMatch",
"SensitivityLabeledFileAction",
"SharePoint",
"SharePointCommentOperation",
"SharePointContentTypeOperation",
"SharePointFieldOperation",
"SharePointFileOperation",
"SharePointListItemOperation",
"SharePointListOperation",
"SharePointSearch",
"SharePointSharingOperation",
"SkypeForBusinessCmdlets",
"SkypeForBusinessPSTNUsage",
"SkypeForBusinessUsersBlocked",
"Sway",
"SyntheticProbe",
"TeamsHealthcare",
"ThreatFinder",
"ThreatIntelligence",
"ThreatIntelligenceAtpContent",
"ThreatIntelligenceUrl",
"UserTraining",
"WDATPAlerts",
"WorkplaceAnalytics",
"Yammer"
)
foreach ($RecordType in $RecordTypes){
Write-Output $RecordType
$UnifiedAuditLog = Search-UnifiedAuditLog -UserIds $userSMTP -StartDate $StartDate -EndDate $EndDate -SessionCommand ReturnLargeSet -ResultSize 5000 -RecordType $RecordType
if ($UnifiedAuditLog){
$UnifiedAuditLog | Select-Object CreationDate, UserIDs, Operations, AuditData | Export-Csv -Path "$OutDir\UnifiedAuditLog_$RecordType.csv" -NoTypeInformation -Append
}
}