-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGet-UserDeletedItems.ps1
More file actions
38 lines (34 loc) · 943 Bytes
/
Get-UserDeletedItems.ps1
File metadata and controls
38 lines (34 loc) · 943 Bytes
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
Param (
[string]
$UserIds,
[System.ValueType]
$StartDate = (Date).AddDays(-3),
[System.ValueType]
$EndDate = (Date).AddDays(1)
)
$deletions = (Search-UnifiedAuditLog `
-StartDate $StartDate `
-EndDate $EndDate `
-ResultSize 5000 `
-UserIds $UserIds `
-Operations 'SoftDelete','MoveToDeletedItems'
)
$output = @()
$global:truncatedRecords = @()
$deletions | ForEach-Object {
$deletion = $_
try {
$auditData = ConvertFrom-JSON $deletion.AuditData
$auditData.AffectedItems | ForEach-Object {
$output += New-Object PSObject -Property @{
Operation = $deletion.Operations
Subject = $_.Subject
Path = $_.ParentFolder.Path
}
}
} catch {
$global:truncatedRecords += $deletion
Write-Warning "Record truncated, thanks Microsoft! Saved in `$global:truncatedRecords."
}
}
$output