My file being uploaded is initiated below, I call $spFile.Item which is a SPListItem to call setFieldValue($spFile.Item,$term)
[Microsoft.SharePoint.SPFile]$spFile = $folder.Files.Add($folder.URL + "/" + $File.Name, [System.IO.Stream]$fileStream, $true)
$spSite = Get-SPSite -Identity $siteURL
$taxonomySession = Get-SPTaxonomySession -Site $siteURL
[Microsoft.SharePoint.Taxonomy.TaxonomyField]$lobField = $spSite.RootWeb.Fields["Lines of Business"]
$termStoreID = $lobField.SspId
$termStore = $taxonomySession.TermStores[$termStoreID]
$termStore.get_Groups() | foreach{if($_.Name -eq "Corporate Store"){$termGroup = $_}}
$termGroup.get_TermSets() | foreach{if($_.Name -eq "Lines of Business"){$lobTermSet = $_}}
$lobTermCollection = $lobTermSet.GetAllTerms()
$lobTermCollection.GetEnumerator() | foreach{if($_.Name -eq $lineofbusiness){[Microsoft.SharePoint.Taxonomy.Term]$lobTerm = $_}}
$lobField.SetFieldValue($spFile.item,$lobTerm)
It's a big mess, but my previous method of doing the same thing in 2013 did not work at all. I always get the error
SetFieldValue : Exception calling "SetFieldValue" with "2" argument(s): "The given guid does not exist in the term store"
At line:1 char:24
+ $lobField.SetFieldValue <<<< ($spFile.Item,$lobTerm)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
How can I set the managed metadata properly for this file I am uploading to a document library on 2010? I have only worked with 2013 before.
I did what this guy said and it didn't work either I should add. Even properly getting the field from the file I add doesn't work. There seems to be a disconnect between the taxonomysession/termstore I am retrieving and the real one since it does not recognize terms I know are in the termset by string value