cannot delete Sharepoint / Teams "Misc" Documents subfolder

David Penna 21 Reputation points
2022-04-01T14:13:36.757+00:00

Hi, in our dept's Sharepoint Documents library, I had created a Misc subfolder a couple of years ago. We no longer need it and want to delete it, but it has no Delete option (every other folder has Delete in-between Add shortcut to OneDrive and Automate options).
189203-capture1.png

Our IT Manager said it's because we once had a Channel in our dept Teams called "Misc", which has since been deleted, although the Misc FOLDER wasn't manually linked to it.

In any event, I tried re-creating the Misc Channel, which didn't enable a Delete option in Sharepoint OR Teams... and what's interesting is that when I then went to delete the Channel again and got this warning:
189098-capture2.png

And the link takes me directly to the Sharepoint Documents' Misc subfolder, even though I never added it to the channel (there doesn't seem to be a way to connect / link a specific Sharepoint Document Library's subfolder to a Teams channel anyway)... so it seems by way of using the id “Misc” for the Sharepoint folder, Teams automatically connected it to the Misc Channel.

And of course there is also no option to Rename the folder (in case renaming it to something other than Misc would solve the issue).

Can anyone advise me how to delete that folder?

Thanks!

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CaseyYang-MSFT 10,461 Reputation points
    2022-04-04T04:56:31.837+00:00

    Hi @David Penna ,

    You could delete this folder with SharePoint PowerShell as a workaround.

    PowerShell commands:

    #Function to Delete all files and Sub-folders of a given Folder  
    Function Empty-SPOFolder([Microsoft.SharePoint.Client.Folder]$Folder)  
    {  
        Try {  
            #Get All Files from the Folder  
            $Ctx = $Folder.Context  
            $Files = $Folder.Files  
            $Ctx.Load($Files)  
            $Ctx.ExecuteQuery()  
        
            #Iterate through each File in the Root folder  
            Foreach($File in $Files)  
            {  
                #Delete the file  
                $Folder.Files.GetByUrl($File.ServerRelativeUrl).Recycle() | Out-Null  
                Write-host -f Green "Deleted File '$($File.Name)' from '$($File.ServerRelativeURL)'"  
            }  
            $Ctx.ExecuteQuery()  
        
            #Process all Sub Folders of the given folder  
            $SubFolders = $Folder.Folders  
            $Ctx.Load($SubFolders)  
            $Ctx.ExecuteQuery()  
               
            #delete all subfolders  
            Foreach($Folder in $SubFolders)  
            {  
                #Exclude "Forms" and Hidden folders  
                If( ($Folder.Name -ne "Forms") -and (-Not($Folder.Name.StartsWith("_"))))  
                {  
                    #Call the function recursively to empty the folder  
                    Empty-SPOFolder -Folder $Folder  
       
                    #Delete the folder  
                    $Ctx.Web.GetFolderById($Folder.UniqueId).Recycle() | Out-Null  
                    $Ctx.ExecuteQuery()  
                    Write-host  -f Green "Deleted Folder:"$Folder.ServerRelativeUrl  
                }  
            }  
        }  
        Catch {  
        write-host -f Red "Error:" $_.Exception.Message  
        }  
    }  
       
    #Variables  
    $SiteURL = "https://your tenant.sharepoint.com/sites/your site name"  
    $ServerRelativeUrl= "/sites/your site name/your library name/your folder name"  
       
    Try {  
        #Get Credentials to connect  
        $Cred= Get-Credential  
       
        #Setup the context  
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)  
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
         
        #Get the web from URL  
        $Web = $Ctx.web  
        $Ctx.Load($Web)  
        $Ctx.executeQuery()  
       
        #Get the Folder object by Server Relative URL  
        $Folder = $Web.GetFolderByServerRelativeUrl($ServerRelativeUrl)  
        $Ctx.Load($Folder)  
        $Ctx.ExecuteQuery()  
       
        #Call the function to empty Folder  
        Empty-SPOFolder $Folder  
       
        #Delete the given Folder itself  
        Write-host  -f Green "Deleting Folder:"$Folder.ServerRelativeUrl  
        $Folder.Recycle() | Out-Null  
        $Ctx.ExecuteQuery()  
    }  
    Catch {  
        write-host -f Red "Error:" $_.Exception.Message  
    }  
    

    Note: Remember to replace your tenant name, your site name, your library name and your folder name in line 47 and line 48

    For Reference: SharePoint Online: Delete All Files and Sub-Folders from a Folder Recursively using PowerShell
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    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.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.