1

So far I have managed to move Document Sets using PowerShell from Document Library A to Document Library B. I found this article: http://www.sharepoint2010blog.nl/2010/07/20/Moving+A+DocumentSet+Through+Code+Pt1.aspx

It works great but only copies the document set to "Document Library B" root.

$moveurl = $movetoList.RootFolder.ToString() + "/" + $docset.Name

So my question is how do I move it into a hierarchy?

With this I should be able to get the folder:

$web = Get-SPWeb http://url
$list = $web.Lists["name"]
$list.Folders[$afolder]

But I don't know how to edit the $movetoList.RootFolder to that i use $afolder insted of Rootfolder.

Would be awesome if someone could help me out! Thanks in advance!

2 Answers 2

2

So I Solved the problem, just wanted to post the script. The Script now moves Document Sets from Location A to Location B. Can be moved into folders aswell.

$moveFromUrl = "Url"
$moveToUrl = "Url"
$moveItemName = "Document Set Name"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

function checkItemToMove ([Microsoft.SharePoint.SPList]$movefromList, [string]$moveToUrl, [string]$moveItemName)
{
    $docsetID = [Microsoft.SharePoint.SPBuiltInContentTypeId]::DocumentSet
    [Microsoft.SharePoint.SPFolder]$docsetToMove = $null 

    $movefromList.Items
    $docSetListItem = $movefromList.Items | where {$_['Title'] -eq $moveItemName}
    $docSetToMove = $docSetListItem.Folder
    $docsetContentTypeId = $docSetListItem.ContentType.Parent.Id

    if($docsetToMove -ne $null -and $docsetContentTypeId -ne $null -and $docsetContentTypeId.ToString().StartsWith($docsetID.ToString())) 
    {
        Write-Host -ForegroundColor Green "Found a docset: " $docsetToMove.Name " Lets move it"
        moveDocSet $docsetToMove $moveToUrl $docsetContentTypeId
    }
    else 
    {  
        Write-Host -ForegroundColor Red "no document set of desired name found:" $moveItemName 
    }
}

function moveDocSet ([Microsoft.SharePoint.SPFolder]$docset, [string]$moveToUrl, [string]$docsetContentTypeId)
{
    $url = $moveToUrl + $docset.Name
    $docset.MoveTo($url)

    [Microsoft.SharePoint.SPList]$moveToList = $site.OpenWeb().GetList($moveToUrl)
    $newDocSetItem = $moveToList.Items | where {$_['Name'] -eq $docset.Name}
    $newDocSet = $newDocSetItem.Folder
    if($newDocset.Exists)   
{

    $newDocset.Item["ContentTypeId"] = $docsetContentTypeId
    $newDocset.Item["HTML File Type"] = "SharePoint.DocumentSet" 
    $newDocset.Item.Update()

    Write-Host -ForegroundColor Green " Document set moved succesfully "
    }
    else {Write-Host -ForegroundColor Red " Failed moving the docset or setting ... "}
}

if($moveFromUrl -eq $null -or $moveFromUrl -eq "") {Write-Host -ForegroundColor Red "No folder to move from"; Exit}
if($moveToUrl -eq $null -or $moveToUrl -eq "") {Write-Host -ForegroundColor Red "No folder to move to"; Exit}
if($moveItemName -eq $null -or $moveItem -eq "") {Write-Host -ForegroundColor Red "No DocumentSet name set"; Exit}

$site=new-object Microsoft.SharePoint.SPSite($moveFromUrl)

[Microsoft.SharePoint.SPList]$movefromList=$site.OpenWeb().GetList($moveFromUrl)

checkItemToMove $movefromList $moveToUrl $moveItemName 
0

Use this

$moveurl = $list.Folders[$afolder].ToString() + "/" + $docset.Name
1
  • Thanks for reply. Tried the same line before but it didn't work. ATM I am trying to do somthing like this: $b = $web.GetFolder($web.Url + "part of url"); $moveurl = $web.Url + "/" + $b.FolderName + "/" + $docset.Name Oct 3, 2013 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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