Remove Drop Off Libraries from Every Site

Applies To: SharePoint 2010

The other day I came across a problem with some missing features on a few of our sites. Some quick searching told me I needed to enable all my sites to use the SharePoint Server Enterprise Features. This is a good thing to do, especially if you’ve just upgraded from 2007 to 2010 or you were using Foundation or Standard Server.

So, I went to Central Administration and clicked on Upgrade and Migration and chose Enable Features on Existing Sites. I was presented with this screen:

So, I checked the box and pressed OK. It took a few hours, but then everything was good to go! Almost…

Turns out I had people asking me what this new Drop Off Library link was on their sites. A quick check showed that EVERY SITE in EVERY SITE COLLECTION in EVERY WEB APPLICATION now had the Content Organizer feature enabled and a Drop Off Library added.

So, I go to Manage Site Features I deactivate the Content Organizer and go to delete the Drop Off Library. No delete option in Library settings. Turns out you need to use something like SharePoint Manager or Powershell to allow the library to be deleted before that link will show up. Regardless, we have hundreds of sites and my sites – All of which now have an unremovable library and unnecessary feature activated.

So, time for some Powershell! I wrote a script (below) that will cycle through all the sites in all the site collections for a given Web Application and disable the DocumentRouting feature (Content Organizer) and delete the Drop Off Library. I was inspired by this forum thread and this blog post.

Additionally, I was also faced with the complication that I had actually activated this feature previously for a few sites and wanted to make sure they weren’t stripped along with everybody else. So I added an ExclusionURLs parameter. I’ll explain more about that and how the rest of the script works in a minute.

The Script

Param(
	[parameter(position=0)]
	[String]
		$WebApplicationURL,
    [parameter(position=1)]
    [Boolean]
        $AnalysisOnly = $true,
	[parameter(position=2)]
	[String[]]
		$ExclusionURLs
)

#Display Exclusion URL information
if($ExclusionURLs -and $ExclusionURLs.Count -gt 0) {
    Write-Host "Excluded URLs:" -foregroundcolor green
    $ExclusionURLs | ForEach-Object {
        Write-Host "     $_" -foregroundcolor green
    }
} else {
    Write-Host "No URL Exclusions" -foreground cyan
}

#Display Feature Information
$feature = Get-SPFeature “DocumentRouting”
Write-Host “Feature ID for Content Organizer is called $($feature.DisplayName)" -foregroundcolor cyan

if($AnalysisOnly) {
    Write-Host "ANALYSIS ONLY" -foregroundcolor red
}

#Go Through Every Site
Get-SPWebApplication $WebApplicationURL | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL | ForEach-Object {

    #Check for Exclusion
    if(!($ExclusionURLs -contains $_.URL)) {
        Write-Host "$_ | $($_.URL)" -foregroundcolor DarkCyan

        #Disable Feature if found
        if ($_.Features[$feature.ID]) {
            Write-Host “  Feature $($feature.DisplayName) Found" -foreground green
            if(!$AnalysisOnly){
                Disable-SPFeature $feature -Url $_.Url -Force -Confirm:$false
                Write-Host “  Feature $($feature.DisplayName) Disabled” -foreground magenta
            }
        } else {
            Write-Host "  Feature $($feature.DisplayName) NOT Found" -foreground yellow
        }

        #Delete Drop Off Library if found
        $list = $_.Lists["DROP OFF LIBRARY"]
        if ($list) {
            Write-Host “  List $list Found” -foregroundcolor green
            if(!$AnalysisOnly){
                $list.AllowDeletion = $true;
                $list.Update()
                $list.Delete()
                Write-Host “  List $list Deleted” -foreground magenta
            }
        } else {
            Write-Host “  Drop Off Library NOT found” -foregroundcolor yellow
        }
    }

}
Write-Host " "
Write-Host "All Done!" -foregroundcolor yellow

You can copy the above script, save it in a text file with a ps1 extension and run it from the console. Assuming you’ve named the file RemoveDropOffLibraries.ps1 you can run it in a couple of different ways:

Analysis Only:

Since I’m the cautious type, I want to know which sites are going to be affected before I actually pull the trigger. So running it with just the Web Application URL will provide you with a list of all sites. Additionally, you’ll be told if a given site has the DocumentRouting feature enabled and if a Drop Off Library was found.

Perform Actions:

If you’re comfortable with the results above, just pass the Web Application URL and $false for the AnalysisOnly parameter. This will do the same list of sites and indicate if the DocumentRouting feature is enabled and if a Drop Off Library was found. Each time the feature is found activated, it gets disabled and you’ll see a message. Additionally, each time a Drop Off Library is found, it gets deleted and you’ll see a message.

Analysis Only with Exclusions:

Exclusions allow you to pass site URLs in a comma separated list. Doing the above command ensures your exclusions are working. Just specify the Web Application URL, $true for AnalysisOnly and then 1 or more exclusion URLs separated only by a comma.

Perform Actions with Exclusions:

This uses the same rules for exclusions as above, but instead of just analyzing, it actually does the work.

Quick Tip:

If you have a lot of sites and want to be able to see the output easily, use the start-transcript and stop-transcript cmdlets like so:

start-transcript -path SomeFile.rtf
...Commands and Output...
stop-transcript

Just replace line 2 with one of the command examples from above.

 

Surely no one else will ever end up in this situation, but just in case – there ya go!

Deleting a Document from a Record Library

Applies To: SharePoint 2010

In setting up a Records Center I was trying out the Content Organizer and Drop Off Library. I configured a Send To location and an Organizer Rule to get my document to my new Record Library. It worked great! However, since this was just a test to make sure everything mapped over correctly, I wanted to delete the test document and I got this error:

This item cannot be deleted, moved, or renamed because it is either on hold or is a record which blocks deletion.
This item cannot be deleted, moved, or renamed because it is either on hold or is a record which blocks deletion.

Uh… so how do I undeclare it? The answer is that with record libraries, all documents are not only automatically declared records, manual declaration/undeclaration is disabled by default. This all makes sense considering this is in the Record Center and it is a Record Library. But to delete your document, you will have to disable these settings (Temporarily).

1. Turn off Automatic Record Declaration

Go to your Library Settings for your Record Library. Under Permissions and Management choose Record declaration settings:

Uncheck the box in the Automatic Declaration section then press OK:

2. Enable Manual Declaration of Records

Go back into the Record declaration settings since the Manaual Record Declaration Availablity section will now be enabled. Choose Always allow the manual declaration of records:

3. Undeclare the Document as a Record

Go back to the Library and choose the document you want to delete. In the drop down menu, choose Compliance Details:

In order to remove the document, it can’t be a record nor be part of any holds. In the compliance details popup remove the document from hold (if necessary) and click the Undeclare record link. In the confirmation dialog choose OK to undeclare.

4. Delete the Document

Kill that sucker.

5. Put Everything Back in Place

Those settings were on the library for a good reason. Once you’ve finished your testing or no longer need to delete any individual records, you should go back to your library settings and reenable the default settings (Follow these steps backward).

If for some reason, you want to delete the Record Library itself. You will need to remove every record from the library following the above steps and then run the “Hold Processing and Reporting” job in Central Admin. This let’s SharePoint know there are no records in there and the standard deletion link will appear in the Library Settings.