Reputation: 1351
I need to restore a massive amount of deleted files back into Sharepoint. Sharepoint is a disgusting beast that should be avoided at all costs, of course, but a client is running it and I need to find a resolution for them.
Connect-SPOService -Url https://clientdomain-admin.sharepoint.com -Credential $userCredential
So far so good.
$Site = Get-SPOSite
Write-Host $Site
Output: Microsoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSite
I am not kidding. So trying a different way:
$SiteUrl = "https://clientdomain.sharepoint.com"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Site = $Context.Site
$RecycleBinItems = $Site.RecycleBin
Write-Host "Total Number of Items:" $RecycleBinItems.Count
Output: "Total Number of Items: 0
I am stuck at this point. Does anyone know how to access the Recycle Bin this way?
Upvotes: 0
Views: 3577
Reputation: 101
Bisclavret's answer worked for me.
I needed to export the list so I added an export path before the query and then "$RecycleBinItems | Export-Csv -Path $FilePath NoTypeInformation" at the end as below.
$FilePath = "C:\Users\Admin\Documents\Restore from recycle bin\restore.csv"
$Context.ExecuteQuery()
$RecycleBinItems | Export-Csv -Path $FilePath
Upvotes: 0
Reputation: 1351
Wow, been messing with this for hours and finally got it. Full code:
$SiteUrl = "https://clientdomain.sharepoint.com"
$AdminUserName = "[email protected]"
$Password = Read-host -assecurestring "Enter Password for $AdminUserName"
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUserName,$Password)
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $Credentials
$Site = $Context.Site
$RecycleBinItems = $Site.RecycleBin
$Context.Load($Site)
$Context.Load($RecycleBinItems)
$Context.ExecuteQuery()
Write-Host "Total Number of Items:" $RecycleBinItems.Count
Output: 14440
Upvotes: 0