-
Notifications
You must be signed in to change notification settings - Fork 106
/
BulkRestoreOnedriveFiles.ps1
76 lines (49 loc) · 1.9 KB
/
BulkRestoreOnedriveFiles.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
<#PSScriptInfo
.VERSION 1.0
.GUID da6d6049-875e-485b-a9c1-4564d327f0cc
.AUTHOR Vikas Sukhija
.COMPANYNAME TechWizard.cloud
.COPYRIGHT Vikas Sukhija
.TAGS
.LICENSEURI https://techwizard.cloud/
.PROJECTURI https://techwizard.cloud/
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES https://techwizard.cloud/
.PRIVATEDATA
===========================================================================
Created with: ISE
Created on: 10/2/2024 1:46 PM
Created by: Vikas Sukhija
Organization:
Filename: BulkRestoreOnedriveFiles.ps1
===========================================================================
#>
<#
.DESCRIPTION
This script will assit in restoring the files in the OneDrive for Business
#>
#################Parameters##########################
Param(
$startDate = "2024-07-20",
$endDate = "2024-07-25",
$onedrivesiteURL
)
#################logs and variables##########################
$log = Write-Log -Name "BulkRestoreOnedriveFiles" -folder "logs" -Ext "log"
Write-log -message "Start ......... Script" -path $log
Connect-PnPOnline -Url $onedrivesiteURL -UseWebLogin
$recycleBinItems = Get-PnPRecycleBinItem
$startDate = Get-Date $startDate
$endDate = Get-Date $endDate
$filteredItems = $recycleBinItems | Where-Object { $_.DeletedDate -ge $startDate -and $_.DeletedDate -le $endDate }
$restorefiles = $filteredItems # you can add filter here if you want | where{$_.Title -like "*.csv"}
foreach ($item in $restorefiles) {
[string]$id = $item.Id
Restore-PnPRecycleBinItem -Identity $id -force
write-log -message "Restored file $($item.Title)" -path $log
}
Write-Log -Message "Script Finished" -path $log
################################################################