I have a document Library.

It contains many columns out of which I want to update the value for managed metadata column.

Suppose, the Value which I want to update is "My Value" and this value "My Value", exists in term store and also in Taxonomy Hidden List.

Below is my code to update the value:

#CAML Query to get Item From Library and Update
        $spQuery = New-Object Microsoft.SharePoint.SPQuery
        $spQuery.ViewFields  ="<FieldRef Name='My_x0020_Prod' />";
        $spQuery.ViewAttributes = "Scope='Recursive'";
        $spQuery.Query = "<Where>                                    
                                    <FieldRef Name='Prod_x0020_ID' />
                                    <Value Type='Text'>" + $prodID  + "</Value>
        foreach ($item in $col)  
           if($item.Count -gt 0)

                $item["My_x0020_Prod"] = "My Value"


This code doesnt update the MMD item in the library and throws an error:

The given guid does not exist in the term store

Now, when I go back to the library and manually update the field for the MMD column, it works fine.

Programatically, this is not working and I think I am missing something.

Should I first get GUID from term store and then update the value in MMD?

2 Answers 2


Yes you cannot update MMD field whose value is not present in termstore

You need to first get the term value which you will be updating

$site = Get-SPSite "http://site"
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termStore = $session.TermStores["TermStore Name"]
$group = $termStore.Groups["Terms"]
$termSet = $group.TermSets["termset"]
$terms = $termSet.GetTerms(number of terms to be retrieved)
$term = $terms | ?{$_.Name -eq "your value"}

And then use $term to update in your code

 $termfield= [Microsoft.SharePoint.Taxonomy.TaxonomyField]$List.Fields["My_x0020_Prod"]

foreach ($item in $col)  
       if($item.Count -gt 0)

            $termfield.SetFieldValue($item, $term)

  • I do not want to update any values in termstore. I just want to update a value for MMD type of column(in a library). Even then, should I goto termstore and get the term value? Commented Mar 3, 2017 at 12:25
  • Yes, the above code does not update value in termstore but gets the value from term store amd then updates a mmd field
    – rjv91
    Commented Mar 3, 2017 at 15:00
  • Thank you for the response. I am working on the suggested code. $term is coming as empty. $_.Name is not a property which could be found. Any suggestions would be really helpful. Thanks Again ! Commented Mar 6, 2017 at 5:07
  • Are you getting any results in the $terms object.Also check if you have given the correct termstore name,group name termset name etc..
    – rjv91
    Commented Mar 6, 2017 at 5:15
  • Termstore Name, Group Name , Termset Name are correct. $termSet.GetTerms(1) does not return anything. I have mentioned (1) as I need only one term. Number of terms to be retrieved is 1 in my case. If I write $termSet.GetAllTerms() then all terms are returned. I need to search based on specific term. Commented Mar 6, 2017 at 5:28
#Create a Taxonomy Session
 $TaxonomySession = Get-SPTaxonomySession -Site $web.Site
 $TermStore = $TaxonomySession.TermStores[$termStoreName]
 $TermGroup = $TermStore.Groups[$termGroupName]
 $TermSet = $TermGroup.TermSets[$termSetName]

 #Below line of code will get the name, GUID and other properties from TermStore
 $Term = $Termset.Terms[$MMDValueToUpdate]

#This is the Library Item OOTB ID of the item which you want to update
 $item = $list.GetItembyID($ItemID)
 if($item.Count -gt 0)
 $MMSField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$item.Fields[$FieldName]
 #If value exists in TermStore
 Write-Host "Updated value as: " $Term.Name -backgroundcolo Green
Write-Host "Could not find termstore properties for : " $MMDValueToUpdate  -backgroundcolo Red

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.