-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSet-Office365Auditing.ps1
42 lines (30 loc) · 1.44 KB
/
Set-Office365Auditing.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
<#
.SYNOPSIS
Turns on the Audit logs, and assign people to view them.
You will need to run this from Powershell Exchange.
You will need to connect usingConnect-EXOPSSession -UserPrincipalName
You will also need to run Enable-OrganizationCustomization first.
.EXAMPLE
.\Set-Office365Auditing.ps1 -Path:'.\data\ViewAuditUsers.csv' -TenantDomain:'<tenant>.onmicrosoft.com'
#>
param(
# The path to the CSV file
[Parameter(Mandatory)][string]$Path,
[Parameter(Mandatory)][string]$TenantDomain
)
#Connect using Exchange Online Powershell
# Show basic information
$InformationPreference = 'continue'
Write-Information -MessageData:"$(Get-Date) Started Enabling Auditing for $TenantDomain."
Write-Information -MessageData:"Creating Group View Audits Only";
New-RoleGroup -Name "View Audits Only" -Roles "View-Only Audit Logs" -Description "Allow the users read only to the Audit Logs" -ErrorAction SilentlyContinue
@($(Import-Csv -path:$Path) | ForEach-Object {
$UserCSV = $PSItem
$UPN = $UserCSV.UserPrincipalName + '@' + $TenantDomain
$displayName = $UserCSV.UserPrincipalName -replace '\.', ' '
Add-RoleGroupMember -Identity "View Audits Only" -Member:$UPN -Confirm:$false -ErrorAction: SilentlyContinue
Write-Information -MessageData:"$($UserCsv.UserPrincipalName) Added"
})
#Turn on Auditing
Write-Information -MessageData:"Turning on Auditing"
Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true