Is it possible to change a value on all libraries within a site. I have multiple libraries where the term name in the store has been changed. However in libraries I have documents tagged with the old term. The view the library is looking for this old term. Can I use powershell to change the filter value on mass for all libraries. Any examples?

1 Answer 1


There are a few things you need to do here.

Get a ref to the Term store and terms:

$site = Get-SPSite http://yoursite
$web = $site.OpenWeb("yourweb")
$session = Get-SPTaxonomySession -Site $site

$list = $web.lists["Documents"]

$field = $list.Fields["TargetField"]
$termStoreId = $field.SspId
$termsetId = $field.TermSetId.ToString()
$termstore = $session.TermStores[$termStoreId]
$termSet = $termstore.GetTermSet($termsetId)
$terms = $termset.GetAllTerms()

Once you have that you need to find the items to replace. You need to get the WSSId of the original term:

$term = $terms | where {$_.Name -eq 'YourOldTerm'}
$WSSId = [Microsoft.SharePoint.Taxonomy.TaxonomyField]::GetWssIdsOfTerm($site, $termstoreid, $termsetId,$term.Id, $false, 1)

Now that you have that you can issue a query to find your items:

$caml = "<Where>
                <FieldRef LookupId='TRUE' Name='YourFieldName' />
                <Value Type='Integer'>$WSSId</Value>
    $query = New-Object Microsoft.SharePoint.SPQuery
    $query.ViewAttributes = "Scope='RecursiveAll'"
    $query.Query = $caml
    $items = $list.GetItems($query)

Loop through the $items get the taxonomy field for each $item:

$fld = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$item.Fields["YourFieldName"]

Get your new value from the original $terms:

$newValue = $terms | where {$_.Name -eq 'New Value'}

And finally set it:

$fld.SetFieldValue($folder.Item, $newValue)

Ideally you should wrap all this in a function. If you don't understand anything let me know and I can do just that when I get some spare time.

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.