Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am creating a Document Set for a library using powershell and that document set contains some mandatory managed metadata fields. I am able to create document set but how can I insert data into those managed metadata fields at runtime?

share|improve this question

3 Answers 3

You have to connect to the term store and then construct a TaxonomyFieldValue and then use the target field's SetFieldValue() method to assign the value.

See here:

regards, KS

share|improve this answer
The link which you have provided is applicable for List managed metadata column. But, I have to add value into Document Set managed metadata column. Still not able to figure out... –  Lalit Kumar Mishra Oct 31 '12 at 3:44
Just for information -- the column in which i have to insert data is a site column which added into the Document Set content type. –  Lalit Kumar Mishra Oct 31 '12 at 3:46

Hope this helps someone.

You have to get a reference to the Managed metadata item from term store as shown below

$someTerm = $term.Terms | where-object {$_.Name -eq "SomeTerm" }

Create the document set as shown below

[Hashtable]$docSetProperties = @{}
$newDocumentSet=Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"TestDocSet",$DocContentType.Id, $docSetProperties )

Get a reference to the inserted document set

$id = $newDocumentSet.Item.ID
$spItem = $list.GetItemById($id)

Get a reference to the taxonomy field from the inserted document set

$taxMMField = $spItem.Fields['YourManagedMetaDataField'] -as   [Microsoft.SharePoint.Taxonomy.TaxonomyField]
$taxMMField.SetFieldValue($spItem, $someTerm)

Call the Update method on the item


This will update the Managed metadata field in the Document Set.

share|improve this answer

Complete sample

$webUrl = "http://portaladdress.local"
$inputDir = "C:\sampledata"

$spWeb = Get-SPWeb $webUrl 
$spsite = $spWeb.Site

$docLibrary = $spWeb.Lists["DocumentLibraryListName"]
$spFolder = $spWeb.GetFolder($docLibrary.rootFolder.URL + "/")

$taxonomySession = Get-SPTaxonomySession -Site $spsite
$taxonomyField = $docLibrary.Fields["TaxononomyFieldName"]
$termStoreID = $taxonomyField.SspId 
$termStore = $taxonomySession.TermStores[$termStoreID]  
$termsetID = $taxonomyField.TermSetId   
$termset = $termStore.GetTermSet($termsetID)


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

### Create Document Set Properties Hashtable   
[Hashtable]$docsetProperties = @{"DescriptionFieldName"="some text"}   
$docsetProperties = @{"DatefiledName"="06/06/2006"} 

### Create new Document Set   
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($spFolder,"documentset title",$cType.Id,$docsetProperties)   

$term = $termset.GetTerms( "TermLabel", $true)
$id = $newDocumentSet.Item.ID;
$spItem = $docLibrary.GetItemById($id);
#this is a critical point: get  a reference to the field by the item instead of using that from the list we got before (ie: $taxonomyField)
$taxMMField = $spItem.Fields['TaxononomyFieldName'] -as [Microsoft.SharePoint.Taxonomy.TaxonomyField];
$taxMMField.SetFieldValue($spItem, $term);

#upload a file into the document set
$FilePath = "$inputDir\FileToBeLoadIntoTheDocumentset.pdf"
$FileName = "FileToBeLoadIntoTheDocumentset.pdf"
$file= Get-Item $FilePath
$spFile = $newDocumentSet.Folder.Files.Add($newDocumentSet.Folder.Url + "/" + $FileName,$file.OpenRead(),$false)
$spFileItem = $spFile.Item 
$spFileItem["Titolo"] = "File title";
$spFileItem.File.CheckIn("checkin comments", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)

share|improve this answer

Your Answer


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.