Link to home
Create AccountLog in
Avatar of gebigler
gebiglerFlag for United States of America

asked on

Outlook 2007 Task List - can't delete nested folders

I tried to copy a Task List to a new folder.  The original Folder had a subfolder.  It was taking forever to copy, so I cancelled only to find it was creating multiple folders within folders (the same 2 folders).  i.e.

folder1
  subfolder1
    folder1
      subfolder1
         folder1
           subfolder1 ... etc.


Now when I try to delete, i get error message below.  I have permission as owner.  If the problem is there are too many tasks to delete in bulk, don't know how to get around that because the nested folders go pretty deep.  Too many to open manually.  It just keeps going!  :)


This error may be the result of trying to delete more than 4,000 messages at one time.  Outlook can delete no more than 4,000 messages when it is working with a server message store.
To avoid this error, delete fewer than 4,000 messages in a single operation.
It is also possible that you do not have the appropriate permissions to delete messages. If you need to delete content from a folder owned by someone else, contact the owner of the folder to obtain the necessary permissions, or have the owner delete the content for you.

Thanks!
Avatar of Blue Street Tech
Blue Street Tech
Flag of United States of America image

Hi gebigler!

Are you connected to an Exchange Server? If so, take if offline (http://office.microsoft.com/en-us/outlook-help/switch-between-working-offline-and-online-HP001232960.aspx).

Once Outlook is offline try to go as deep as you can and delete from there and work your way upward til you get to the original directories.

Import/Export tasks to move large items. (http://office.microsoft.com/en-us/outlook-help/import-outlook-items-from-an-outlook-data-file-pst-HA102505743.aspx) except select only the directories you want to import after you export them.

Let me know how it goes.
Avatar of gebigler

ASKER

I'll share some of the things I tried that didn't work for me, but may work for someone else.

-  I tried "moving" to deleted folder.  I was able to move, but couldn't delete from deleted folder.  

-  I created a .pst file and tried moving to .pst, thinking I could just close and delete the .pst once it was moved.  It seemed to move it, but for some reason it left a copy in my public folder.  

-  I found this script that I was going to modify, but I didn't have to resort to rewriting this script.  I'm posting it in case it helps someone else.

http://letsexchange.blogspot.com/2012/02/infinite-loop-of-nested-folders.html

Here's the script:  

WARNING: as with every script, make sure you test it properly before running it for a live user!!!


You can also find the script in the Microsoft TechNet Script Repository: Delete Outlook Folders Bottom-Up

# Script: DeleteFoldersBackwards.ps1
# Purpose: This scripts deletes every folder and subfolders for a specific top-folder starting from the last one
# Author: Nuno Mota
# Date:  Feb 2012

[String] $mbxName = "motan@parliament.uk"
[Int] $intCount = 0

[String] $dllPath = "E:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
[Void] [Reflection.Assembly]::LoadFile($dllPath)

$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$Service.AutodiscoverUrl($mbxName, {$True})

# This is the root folder from where we want to start searching for the folder we want to delete.
# Once we find it, then we will go recursively down that folder.
# Other option would be to get the FolderID and start the search straight from there
$RootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox, $mbxName)
#$RootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root, $mbxName)
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service, $RootFolderID)

$FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)
$FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
$Response = $RootFolder.FindFolders($FolderView)

# Go through all folders under the Inbox folder looking for the folder we want to delete
ForEach ($folder in $Response.Folders)
{
 # Check if the current folder is the folder we want to delete
 If ($folder.DisplayName -eq "Pictures of Y")
 {
  # Found the folder, so start a new Deep search across all its sub-folders
  $FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(3000)
  $FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
  $Response = $folder.FindFolders($FolderView)
  $RootFolder = $folder
 
  # Loop to go through all sub-folders while there are any
  While ($($Response.Folders).Count -gt 0)
  {
   # Get the last folder so we can then delete it (not very efficient...)
   ForEach ($folder in $Response.Folders)
   {
    #$folder.DisplayName
    $lastFolder = $folder
   }

   Write-Host "Deleting", $lastFolder.DisplayName
   $lastFolder.Delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete)
   $intCount++
   Write-Progress -Activity "Deleting Folders" -Status "Folders Deleted: $intCount"

   $Response = $RootFolder.FindFolders($FolderView)
  }

  # Delete the top folder and exit the first ForEach
  #Write-Host "Deleting Top ""$($RootFolder.DisplayName)"""
  $RootFolder.Delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete)
  Break
 }
}
ASKER CERTIFIED SOLUTION
Avatar of gebigler
gebigler
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Diverseit's answer would've worked if I had been able to get to that final folder.  So that may work for someone else.  My solution was very similar.  

If you know vb6, I'd also suggest googling "search outlook folder recursively" and modifing the code to delete the final folder.