I'm trying to delete all the second stage bins of all Sites in Sharepoint Online available.
My idea is to get all the sites via Get-SPOSite | Select URL
and process them with a foreach
loop:
#Load SharePoint Online Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
##Global Vars
$UserName = "XXX"
$Password = "XXX"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $(convertto-securestring $Password -asplaintext -force)
##Connect to SPOnline
Connect-SPOService -Url https://XXX-admin.sharepoint.com -Credential $Credentials
##Variables for Processing
$Sites = Get-SPOSite | Select URL
##Go for every item.
foreach ($Site in $Sites) {
Try {
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site) ##Context for deletion = SiteURL
$Context.Credentials = $Credentials
$Context.Site.RecycleBin.DeleteAllSecondStageItems()
$Context.ExecuteQuery()
Write-Host "Done: " + $Site
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Yellow
}
}
Now, this throws an Error in catch
(Sorry for german):
Error: Für "ClientContext" und die folgende Argumenteanzahl kann keine Überladung gefunden werden: "1"
Trying to translate into english: Error: There can't be an overload for "ClientContext" and the following number of arguments: 1
I think overload is a translation error in german. Maybe "overlap"?
I think it's basically saying that $Site is not an Uri. What can I do?
Greetz