Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a SharePoint 2010 Discussion Board and it has many Discussions. Would like to move a discussion from the discussion board to another in the same location (under same site collection).

I managed to move the discussion and changed the author of the discussion from System Account to corresponding user account however could not change the author/editor for the replies

I have used the below PS script to do this.


[void][reflection.assembly]::Loadwithpartialname("Microsoft.SharePoint")
$spsite=[Microsoft.SharePoint.SPSite]("https://Teamssite/")
$spweb = $spsite.openWeb()

$spList = $spweb.Lists["Discussion Board"]
$spItem = $spList.GetItemById(273)

$spUser = $spweb.EnsureUser("myDomain\Userx")
$spItem["Author"]=$spUser
$spItem["Editor"]=$spUser
$spItem.SystemUpdate()

$query=new-object Microsoft.SharePoint.SPQuery
$spFolder = $spItem.Folder;
$query.Query = "";
$query.Folder = $spFolder;
$query.RowLimit = 1;
$spReplies = $spList.GetItems($Query);
$spReply = $spReplies[0]
$spReply["Author"] =$spUser
$spReply["Editor"] =$spUser
$spReply.SystemUpdate()

Still, It is showing the System Account for the replies. What am I missing? Is there any other way of doing it?

share|improve this question
    
I have the same problem when saving the Discussion as a template with content. After I upload the template and create a new Discussion using the template (in a different site collection), all the Created By and Created metadata use the same data (i.e. the author responsible for and date/time of the Discussion creation). –  user2491 Feb 23 '11 at 19:55
    
@acguitarte - this is expected because you are creating new discussion and saved content serves just as template (plus users ids are not the same across collections). If you need to migrate Discussion board form one site collection to another you will need more complex script then one I provided. There are some additional issues to address (users, permissions etc.) –  Vedran Rasol Aug 10 '11 at 23:51

2 Answers 2

I am a bit puzzled with your script so I decide to find another way :)

Discussion board is tricky to deal with. Discussion are folders and Messages are items inside folders (very simple explanation). Best way to migrate one Discussion from source to destination list is to recreate new Discussion on destination list and then to recreate all Messages inside it.

So here is script that will do the job:

Add-PSSnapin Microsoft.SharePoint.PowerShell

$web = Get-SPWeb "http://TeamSite"
$sourceList = $web.GetList("http://TeamSite/Lists/source/")
$destinationList = $web.GetList("http://TeamSite/Lists/destination/")

#Get desired discussion by Name (or use some other identifier eg. ID)
$sourceDiscussion = $sourceList.Folders | Where-Object {$_.Name -eq "My cool subject"}

#Add new discussion to destination list
$destinationDiscussion = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($destinationList.Items, $sourceDiscussion.Title)
#Copy basic field values (you can copy some custom fields if needed)
$destinationDiscussion["Body"] = $sourceDiscussion["Body"]
$destinationDiscussion["Author"] = $sourceDiscussion["Author"]
$destinationDiscussion["Editor"] = $sourceDiscussion["Editor"]
$destinationDiscussion["Modified"] = $sourceDiscussion["Modified"]
$destinationDiscussion["Created"] = $sourceDiscussion["Created"]
#Add discussion
$destinationDiscussion.SystemUpdate($false)

#Get all discussion messages (maybe there is better way to get it but this works)
$caml='<Where><Eq><FieldRef Name="ParentFolderId" /><Value Type="Integer">{0}</Value></Eq></Where>' -f $sourceDiscussion.ID
$query = new-object Microsoft.SharePoint.SPQuery
$query.Query = $caml
$query.ViewAttributes = "Scope='Recursive'";
$sourceMessages = $sourceList.GetItems($query)

foreach ($sourceMessage in $sourceMessages) {
    #Add new message to discussion
    $destinationMessage = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussionReply($destinationDiscussion)
    #Copy basic field values (you can copy some custom fields if needed)
    $destinationMessage["Body"] = $sourceMessage["Body"]
    $destinationMessage["TrimmedBody"] = $sourceMessage["TrimmedBody"]
    $destinationMessage["Author"] = $sourceMessage["Author"]
    $destinationMessage["Editor"] = $sourceMessage["Editor"]
    $destinationMessage["Modified"] = $sourceMessage["Modified"]
    $destinationMessage["Created"] = $sourceMessage["Created"]
    #Add message
    $destinationMessage.SystemUpdate($false)
}

As you can see this script migrates original users and dates to destination.

share|improve this answer
1  
The biggest trick to moving discussions is making sure that, as Vedran has done, you use the SPUtility class for Discussions. If you do not, even if it appears to have migrated properly, you will have issues like reply counts not registering, some views not working properly, queries failing, replies not connecting properly, and similar. While I haven't tested Vedran's script, the fact he uses these helper utilities should definitely put you on the right path. –  Mike Redden Aug 11 '11 at 1:18

Thanks for the post, I have tweaked the script a bit to loop through all discussion items in a discussion board and move them to a new list.

    # Migration of a discussion forum to a new list
    # to overcome commenting issue caused by Meta-Vis 
    # Migration

    #Region Load SharePoint Snapin
    $ver = $host | select version
    if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}
    Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    #EndRegion

    $webURL = "http://yoursiteurl"
    $sourceList = "https://sourcelisturl"
    $destList = "https://destinationlisturl"

    # Do not edit below this line
    $web = Get-SPWeb $webURL
    $sourceList = $web.GetList($sourceList)
    $destinationList = $web.GetList($destList)

    $sourceListItems = $sourceList.Folders

    foreach($item in $sourceListItems)
    {
        write-host $item['ID']
        #Get desired discussion by ID (or use some other identifier eg. ID)
        $sourceDiscussion = $sourceList.Folders | Where-Object {$_.ID -eq $item['ID']}

        #Add new discussion to destination list
        $destinationDiscussion = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($destinationList.Items, $sourceDiscussion.Title)
        #Copy basic field values (you can copy some custom fields if needed)
        $destinationDiscussion["Body"] = $sourceDiscussion["Body"]
        $destinationDiscussion["Author"] = $sourceDiscussion["Author"]
        $destinationDiscussion["Editor"] = $sourceDiscussion["Editor"]
        $destinationDiscussion["Modified"] = $sourceDiscussion["Modified"]
        $destinationDiscussion["Created"] = $sourceDiscussion["Created"]
        #Add discussion
        $destinationDiscussion.SystemUpdate($false)

        #Get all discussion messages (maybe there is better way to get it but this works)
        $caml='<Where><Eq><FieldRef Name="ParentFolderId" /><Value Type="Integer">{0}</Value></Eq></Where>' -f $sourceDiscussion.ID
        $query = new-object Microsoft.SharePoint.SPQuery
        $query.Query = $caml
        $query.ViewAttributes = "Scope='Recursive'";
        $sourceMessages = $sourceList.GetItems($query)

        foreach ($sourceMessage in $sourceMessages) {
            #Add new message to discussion
            $destinationMessage = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussionReply($destinationDiscussion)
            #Copy basic field values (you can copy some custom fields if needed)
            $destinationMessage["Body"] = $sourceMessage["Body"]
            $destinationMessage["TrimmedBody"] = $sourceMessage["TrimmedBody"]
            $destinationMessage["Author"] = $sourceMessage["Author"]
            $destinationMessage["Editor"] = $sourceMessage["Editor"]
            $destinationMessage["Modified"] = $sourceMessage["Modified"]
            $destinationMessage["Created"] = $sourceMessage["Created"]
            #Add message
            $destinationMessage.SystemUpdate($false)

        }

    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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