title: How to update SharePoint enterprise keywords with multiple values using powershell?
body: <p>I'm trying to write a powershell script that looks at a user defined variable and updates the enterprise keywords for each item in a list that matches that value.</p>
  
  <p>For instance, say you have a page in SP that has the managed metadata keywords: new, fresh, clean
  I want a script that asks a user what keyword they want to swap out. So a user would specify a variable as: fresh and another variable as: fresher and it would update any item with the keyword fresh to fresher.</p>
  
  <p>Here's what I 've used before but doesn't work now because there are mutliple values:</p>
  
  <pre><code>Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
  $webURL = &lt;MY SP URL&gt;
  $listName = &lt;MY LIST NAME&gt;
  $web = Get-SPWeb $webURL
  $list = $web.Lists[$listName]
  $listitems = $list.items 
  $session = Get-SPTaxonomySession -Site $web.Site
  $termStore = $session.TermStores["Managed Metadata Service"]
  $group = $termStore.Groups["Resources"]
  $termset = $group.TermSets["Wiki Categories"]
  $terms = $termSet.GetTerms(100)
  $wiki1 = read-host "Enter the wiki category you want to update"
  $wiki2 = read-host "Enter the replacement wiki category"
  
  $term = $terms | ?{$_.name -eq $wiki2}
  
  
  Foreach($item in $listitems) 
  {$wiki = $item["Wiki Categories"]
      if($wiki.label -eq $term) 
      { 
          $spitem = [Microsoft.SharePoint.SPListItem]$item;
      $taxfield = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$spitem.Fields["Wiki Categories"]
          $taxfield.SetFieldValue($spitem, $term)
  
      $spitem.Update() 
      $spitem.File.Publish("True")
      } 
  }
  </code></pre>
  
  <p>I'm pretty sure the issue is with this line: </p>
  
  <pre><code>$term = $terms | ?{$_.name -eq $wiki2}
  </code></pre>
  
  <p>And this line: </p>
  
  <pre><code>$taxfield.SetFieldValue($spitem, $term)
  </code></pre>