Delete a folder in SharePoint using PowerShell

Scenario

Need to delete General folder in group site named TestKen

spo-ps-delete-folder-img-1

Steps

1. Run below code blocks line by line in a PowerShell console.

Ensure to change domain and the password part


Set-ExecutionPolicy Unrestricted

$User = "[email protected]"

$PWord = ConvertTo-SecureString -String "yourpassword" -AsPlainText -Force

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

Install-Module SharePointPnPPowerShellOnline

Connect-PnPOnline -Url "https://yourdomain.sharepoint.com/sites/TestKen" -Credentials $Credential
    
Remove-PnPFolder -Name "General" -Folder "Shared Documents" -Force

Disconnect-PnPOnline

2. Check the example below in which I used my test tenant.

spo-ps-delete-folder-img-2

3. Confirm if it is working. In my test instance General folder no longer exist after completing step 1 and refreshing the browser.

spo-ps-delete-folder-img-3

References