I am using this to upload documents to sharepoint library. Is it possible to update managed metadata type columns after adding files to document library. if yes, how.

I am using SP 2010 and powershell

$siteUrl = "http://sharepoint/"
$listName = "Site Assets"

$fileName = "OfferApp.xap"
$filePath = "OfferApp.Web\ClientBin\" + $fileName

$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb()

$list = $web.Lists[$listName]

$fileCollection = $list.RootFolder.Files

$file = Get-Item $filePath
$stream = $file.OpenRead()
$spListItem = $fileCollection.Add($file.Name, $stream, $TRUE)

$spListItem["Managed-metadata type column 1"] = "Second Item"
$spListItem["Managed metadata type column 2"] = "My Text for second item"

"Uploaded " + $file.Name
if ($stream) {$stream.Dispose()}    

if ($web) {$web.Dispose()}
if ($site) {$site.Dispose()}
  • This blog is somewhat close blogs.msdn.com/b/kaevans/archive/2012/02/15/… but still lacking what I need to do. I am supplying value from a csv file. so this wont work. $term = $terms | ?{$_.Name -eq "Newsfeed"} Commented Jun 22, 2012 at 4:18
  • The link you mentioned is doing exactly what you are looking for. Replacing "Newsfeed" with your value from csv should do the job.
    – sssreddy
    Commented Jun 22, 2012 at 4:47

1 Answer 1


I take it that it is the metadata retrieval part that is the problem? First you have to add the file, call update() and then cast the item as necessary. The following code deals exclusively with the retrieval of a metadata term based on an identical text from a csv (or whatever) and assumes you already have a spWeb object instantiated called $web and the exact string of the MMS term coming out of the CSV and held in $valueFromCSV

#Setup TermStore objects
$tSession = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($web.Site)
$tStore = $tSession.TermStores["Managed Metadata Application"]
$tGroup = $tStore.Groups["Group Name"]
$tSet = $tGroup.TermSets["Term Set Name"]

#Termset <> collection of term objects, therefore:

#Get List of terms
$tSetList = $tSetSpecifics.GetAllTerms()
$tTerm = $tSetList | ?{$_.Name -eq $valueFromCSV}

Hope this helps. Had me tripped up for a long time.

Your Answer

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

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