Wednesday, September 28, 2016

SharePoint Online: How to Delete a Folder using PowerShell

Requirement: SharePoint Online PowerShell to Delete Folder

SharePoint Online PowerShell to Delete Folder

How to delete a folder in SharePoint Online:
Simply select the folder from list or library, and then you can delete a folder either from toolbar "delete" button or from the context menu's delete option.
SharePoint Online PowerShell Delete Folder
Confirm the delete prompt and you are done!

SharePoint Online PowerShell to Delete Folder
Here is the PowerShell to remove a folder from list or library in SharePoint Online.
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking
#Variables for Processing
$SiteUrl = ""
$FolderURL="Shared Documents/Project 2020"

Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Ctx.Credentials = $Credentials
    $Web = $Ctx.Web

    #Get the folder object from given URL
    #Delete the folder

    Write-host "Folder deleted Successfully!" -ForegroundColor Green
Catch {
    write-host -f Red "Error deleting Folder!" $_.Exception.Message

Similarly, you can delete any sub-folder by setting the FolderURL parameter in the above script.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...