#Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
# Connect-PnPOnline –Url https://mysite-admin.sharepoint.com –UseWebLogin
# Get-PnPTenant
Connect-PnPOnline -Url https://mysite.sharepoint.com/engineering –UseWebLogin
$now = (Get-Date)
Write-Host "ManageRecycleBin.Restore() : START at: " (Get-Date)
$currentSubwebs = Get-PnPSubwebs
Write-Host "Web Count: " $currentSubwebs.Count
#set the restore date to yesterday
$today = (Get-Date)
$restoreDate = $today.date.AddDays(-18)
#Write-Host "RecycleBin.Count: " (Get-PnPRecycleBinItem).count
Write-Host "restoreDate: " $restoreDate
#(Get-PnPRecycleBinItem).count
#get all items that are deleted yesterday or today, select the last 10 items and display a list with all properties
# Get-PnPRecycleBinItem | ? DeletedDate -gt $restoreDate | select -last 10 | fl *
#Filter by Date
#$today = (Get-Date)
# $date1 = $today.date.addDays(-4)
#$date2 = $today.date.addDays(-6)
# DOES NOT WORK : DeletedDate : The term 'DeletedDate' is not recognized as the name of a cmdlet, function, script file, or operable program
#Get-PnPRecycleBinItem | Where-Object { DeletedDate -gt $date2 -and DeletedDate -lt $date1} | select -last 10 | fl *
#Filter on user
#$Get-PnPRecycleBinItem -FirstStage | ? DeletedByEmail -eq 'john@contoso.com'
#Filter on file type
# Get-PnPRecycleBinItem -FirstStage | ? LeafName -like '*.docx'
#Export results to CSV
# Get-PnPRecycleBinItem | ? {$_.DeletedDate -gt $restoreDate -and $_.DeletedByEmail -eq 'john@contoso.com'} | Export-Csv c:\temp\restore.csv
#Restoring the files
# Get-PnPRecycleBinItem -firststage | ? {$_.DeletedDate -gt $restoreDate -and $_.DeletedByEmail -eq 'john@contoso.com'} | Restore-PnpRecycleBinItem -Force
#Filter on file type
#Get-PnPRecycleBinItem | ? DirName -like '*engineering/*' | select -last 10 | fl *
Write-Host "Get-PnPRecycleBinItem:START... " (Get-Date)
#Get-PnPRecycleBinItem | ? {$_.DeletedDate -gt $restoreDate -and $_.DirName -like '*engineering/Active Projects/*'} | select -last 10 | fl *
Get-PnPRecycleBinItem | ? {$_.DeletedDate -gt $restoreDate -and $_.DirName -like '*engineering/Active Projects/*'} | Export-Csv C:\temp\20190202.00.csv
#Get-PnPRecycleBinItem | ? {$_.DeletedDate -gt $restoreDate -and $_.DeletedByEmail -eq 'john@contoso.com'} | select -last 10 | fl *
# ERROR below,
#Get-PnPRecycleBinItem | ? DeletedDate -gt $restoreDate -and DirName -like '*engineering/*' | select -last 10 | fl *
#Get-PnPRecycleBinItem | Where-Object { DeletedDate -gt $restoreDate -and DirName -like '*engineering/*'} | select -last 10 | fl *
Write-Host "Get-PnPRecycleBinItem:START... " (Get-Date)
Write-Host "ManageRecycleBin.Restore() : DONE at: " (Get-Date)