Everyone knows how to access Recycle bin of a site in SharePoint. But unfortunately SharePoint provides a bad view there. You can neither filter nor create a custom view. Assume that you have a ton of files in Recycle bin and you just want to restore the files which meet some criteria. The scenario is to restore all the files which deleted by Tom Cat and deleted on 23rd Oct
We have the script following:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
$SiteUrl = "https://abc.sharepoint.com/sites/xxx"
$UserName="xyz@abc.onmicrosoft.com"
$Password ="******"
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $credentials
$Site = $Ctx.Site
$Ctx.Load($Site)
$RecycleBinItems = $Site.RecycleBin
$Ctx.Load($RecycleBinItems)
$Ctx.ExecuteQuery()
$a = $RecycleBinItems | Where { $_.DeletedDate -eq "10/23/2018" -and $_.DeletedByName -eq "Tom Cat"}
$Ctx.ExecuteQuery()
Write-Host "Total Number of Items:" $a.Count
# using for loop to restore the item one by one
Foreach($i in $a)
{
$i.Restore()
$ctx.ExecuteQuery()
Write-Host $i.Title " was restored" -ForegroundColor Yellow
}
#>
There are some properties you may need: AuthorEmail, AuthorName, DeletedByEmail, DirName, Id, LeafName, Title
Comments