1

I have been trying to create multiple Document Sets using Powershell from a csv file.

The script creates the Document Sets with the correct Name but doesnt set them up with the Metadata needed for the document set.

For example

I am creating 100 document sets - Each with a Unique Name and should have certain properties populated at creation. Project Number Project Lead Porfolio Lead

However i cannot get the 3 fields above to populate in the Respective Columns even though they are part of the content type for the Document Set.

$csv = import-csv C:\Projects.csv

#Script settings
$webUrl = "http://spprojects/"
$listName = "New Doc Set"


### Get web and list
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listName]

### Get Document Set Content Type from list
$cType = $list.ContentTypes["MY Doc Set"]

# Create desired number of subfolders
foreach ($line in $csv)
{
$pn = $line.PorfoiloLead
$PPn = $line.ProjectLead
$name = $line.ProjectNumber
[Hashtable]$docsetProperties = @{}
$docsetProperties.add('PortfolioLead',$pn)   
$docsetProperties.add('ProjectLead',$ppn) 

    $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,$Name,$cType.Id, $docsetProperties)
write-host "$name ... created"
}

$web.Dispose()

I have tried the example script located at http://www.the-north.com/sharepoint/post/Create-Multiple-Document-Sets-with-Powershell and that has the same behaviour of creating the Doc Sets but not importing the data into the columns for the Document set.

However i can see when I look to call the Doc Set Properties that it has been set there - however this is not displaying at all in the Library when i view it in the browser.

Hopefully I'm just having a bad day (or 2) and this is a relatively simple issue.

Thanks in advance

1

Try to create document set first and then user the resulting object to update the metadata.

i.e.

 $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,$Name,$cType.Id, $docsetProperties)

// set properties 

// update item 

  write-host "$name ... created"

I have not tried to execute the powershell but had simple steps through C# code.

  • Hi Monica, I have tried some methods to then update this property including $newDocumentSet.Folder.Properties["PortfolioLead"]=$pN $newDocumentSet.Folder.Update() $list.Update() $web.Update() However this still doesnt force it through when accessing via Browser (although i can see it in the Properties of the Folder when i check this via Powershell) – GettingMyHeadAroundPSScripting Nov 26 '14 at 13:01
1

I found the issue - I have to use the Internal Name for the Field Which in this case was the name1

$newDocumentSet.Folder.Properties["PortfolioLead1"]=$pN
$newDocumentSet.Folder.Properties["ProjectLead1"]=$ppN
$newDocumentSet.Folder.Update()
$list.Update()
$web.Update()

Once i have included it this was it is now updating as originally required.

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.