Hi @Aase Nomad ,
According to your PowerShell error message, you are not able to delete some specific files in the folder. About Exception calling "ExecuteQuery" with "0" argument(s)" "File Not Found." error, you could try to change the name of the error file then delete it again.
Did you run SharePoint Online Management Shell as a administrator? Some files may need administrator permission to delete.
You could use following PnP PowerShell to bulk delete files in SharePoint Online.
#Parameters
$SiteURL = "https://xxx.sharepoint.com/sites/xxx"
$ListName = "xxx"
#Connect to the Site
Connect-PnPOnline -URL $SiteURL -Interactive
#Get the web & document Library
$Web = Get-PnPWeb
$List = Get-PnPList -Identity $ListName
#Function to delete all items in a folder - and sub-folders recursively
Function Delete-AllFilesFromFolder($Folder)
{
#Get the site relative path of the Folder
If($Folder.Context.web.ServerRelativeURL -eq "/")
{
$FolderSiteRelativeURL = $Folder.ServerRelativeUrl
}
Else
{
$FolderSiteRelativeURL = $Folder.ServerRelativeUrl.Replace($Folder.Context.web.ServerRelativeURL,[string]::Empty)
}
#Get All files in the folder
$Files = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeURL -ItemType File
#Delete all files
ForEach ($File in $Files)
{
Write-Host ("Deleting File: '{0}' at '{1}'" -f $File.Name, $File.ServerRelativeURL)
#Delete Item
Remove-PnPFile -ServerRelativeUrl $File.ServerRelativeURL -Force -Recycle
}
#Process all Sub-Folders
$SubFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeURL -ItemType Folder
Foreach($Folder in $SubFolders)
{
#Exclude "Forms" and Hidden folders
If( ($Folder.Name -ne "Forms") -and (-Not($Folder.Name.StartsWith("_"))))
{
#Call the function recursively
Delete-AllFilesFromFolder -Folder $Folder
}
}
}
#Get the Root Folder of the Document Library and call the function
Delete-AllFilesFromFolder -Folder $List.RootFolder
For Reference: SharePoint Online: Delete All Files in a Document Library using PowerShell
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.