question

DavidPenna-7759 avatar image
0 Votes"
DavidPenna-7759 asked WendyLi-MSFT edited

cannot delete Sharepoint / Teams "Misc" Documents subfolder

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][1]

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][2]

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!
[1]: /answers/storage/attachments/189203-capture1.png
[2]: /answers/storage/attachments/189098-capture2.png

office-sharepoint-onlineoffice-teams-windows-itpro
capture1.png (20.6 KiB)
capture2.png (24.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

CaseyYangMSFT-4714 avatar image
1 Vote"
CaseyYangMSFT-4714 answered WendyLi-MSFT edited

Hi @DavidPenna-7759,

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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @DavidPenna-7759,

Is there any progress on this thread? Please comment here if you still need help.

0 Votes 0 ·

Hi @CaseyYangMSFT-4714 thanks for your answer, unfortunately as I am a user not IT / admin I would not have access to SharePoint PowerShell, but I can suggest this to our IT Manager. Seems odd that there is no way through usual use of Teams or SharePoint to delete a folder.

0 Votes 0 ·

Hi @DavidPenna-7759,

Thanks for your reply, Comment here if you still need any help.

0 Votes 0 ·

@DavidPenna-7759 I am checking to see if you or your IT manager has tried Casey's answer. If you have any updates, please feel free to reply. :)


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

0 Votes 0 ·