Hi @Ernesto Martínez •
Thanks for the post.
You could refer to the following PowerShell command template to delete folder with files in SharePoint Online:
#Config Variables
$SiteURL = "your-site-url"
$ListName ="listname"
$FolderServerRelativeURL = "/sites/sitename/listname/foldername"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get All Items from Folder in Batch
$ListItems = Get-PnPListItem -List $ListName -FolderServerRelativeUrl $FolderServerRelativeURL -PageSize 2000 | Sort-Object ID -Descending
#Powershell to delete all files from a folder
ForEach ($Item in $ListItems)
{
Remove-PnPListItem -List $ListName -Identity $Item.Id -Recycle -Force
Write-host "Removed File:"$Item.FieldValues.FileRef
}
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
For more information about Delete All Files and Sub-Folders from a Folder Recursively using PowerShell in SharePoint Online
I hope I can offer you a better experience next time if I have a chance to work with you again.
Yours faithfully,
Renjie Sun
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.