I'm attempting to run a basic PowerShell script to fix a lot of broken "Send To" destination links that resulted from a site migration from one farm to another.

I wanted to proof-of-concept this on just one document first. As it turns out, there seems to be no way to fix existing links in the collection -- you have to do an SPCopyDestinations.Add() to add the new, correct link into the collection and then SPCopyDestinations.Remove() the existing, broken link.

However, I cannot seem to get the SPCopyDestinationCollection of the item to persist the newly added values to the database.

Here is the PowerShell I ran to try to add a new SPCopyDestination to an item's collection:

PS C:\users\ryan\desktop> $web = get-spweb http://dev.demo.com/sites/sendtoscript
PS C:\users\ryan\desktop> $list = $web.Lists["Original Documents"]
PS C:\users\ryan\desktop> $list.Items[0].CopyDestinations.Add("http://dev.demo.com/sites/sendtoscript/originaldocuments/folder1/doc1.docx", [Microsoft.SharePoint.SPCopyDestinationType]::Update, "")

Url        : http://dev.demo.com/sites/sendtoscript/originaldocuments/folder1/doc1.docx
LeafName   : doc1.docx
FolderUrl  : http://dev.demo.com/sites/sendtoscript/originaldocuments/folder1
Type       : Update
ModifiedBy : 1
CreatedBy  : 1
Id         : 4517a08f-1cc2-4f77-b123-7e7c44373824
Comment    : 
Collection : {4517a08f-1cc2-4f77-b123-7e7c44373824}

PS C:\users\ryan\desktop> $list.Items[0].Update()

However, upon inspecting the SPCopyDestinationCollection of the item after this, there is nothing there:

PS C:\users\u582290\desktop> $list.Items[0].CopyDestinations
PS C:\users\u582290\desktop> 

Any ideas?


We pursued this one in a Micrsoft Premier development case and it turns out there is a bug in PowerShell that causes this method not to work. The underlying method in C# does work, though, it's just PowerShell where the problem occurs. We've escalated this one as a bug to the product team. (This bug is also present in PowerShell for SharePoint 2013.)

UPDATE: Turns out after much more investigation that it was not a bug in PowerShell as originally thought, instead you need to utilize an Assignment Collection to get this to work. Here is the PowerShell code to get this to work properly:

Add-PSSnapin microsoft.sharepoint.powershell -ea 0
Start-SPAssignment -AssignmentCollection $current
$url = 'http://dmvsp2013:9000/cases/frank/'
$web = get-spweb $url -AssignmentCollection $current
$updatetype = [Microsoft.SharePoint.SPCopyDestinationType]::Update
$sourcefile = $web.GetListItem("/cases/frank/source/csharp3.syn")
$desturl = 'http://dmvsp2013:9000/cases/frank/dest/csharp3.syn'
$sourcefile.CopyDestinations.Add($desturl, $updatetype, "PowerShell")

Well, according to this page at Microsoft, to create a "Send To" link for an item, you actually have to go into the library settings. This, to me, would imply that the SPCopyDestinationCollection is actually on the list object, not the item. So maybe you have to update the list?

That's just a guess, though.

And as far as nothing being in the collection, did you try





SPCopyDestinationCollection members on MSDN

  • I did try the indexer and the Count above like you showed, but they return nothing and 0, respectively. Also I checked into the potential that you have to add to the library's Send To locations first before you can an SPCopyDestination to an items collection of destinations, but that proved a dead end, too. (Sidenote: If you do a Send To > Other Location on an item through the UI, it does not add it to the library's locations; those are more there so users can pick from them.) Thanks for the suggestions! – Ryan Spletzer Oct 11 '13 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.