I have been tasked to update metadata fields in a document library by reading inputs from a CSV file. Based on my little understanding of powershell, I have written the code below but it doesn't work. I hope someone can help me. Sorry if this is not an appropriate forum for this.
Add-PSSnapin Microsoft.SharePoint.PowerShell;
$siteobj = new-object Microsoft.SharePoint.SPSite("http://myServer:9600/sites/custdocstore1")
$web = Get-SPWeb "http://myServer:9600/sites/custdocstore1"
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($siteobj)
$CRMCols = Import-Csv "G:\Backup files\MetadataUpdateFromCRMToSharePointFew.csv";
#Getting the term (new value) to which we want to update the column
$termstore = $session.TermStores["Managed Metadata Service"];
$group = $termstore.Groups["MyCompany Customer Document Management"];
$termset = $group.TermSets["Document Category"];
#List/Library we want to update
$list=$web.Lists["Documents"];
$taxfield = $list.Fields["Doc Category"] -as [Microsoft.SharePoint.Taxonomy.TaxonomyField];
#Assign CSV column values to variables
foreach($CRMCol in $CRMCols)
{
$CRMOrg = $CRMCol.Organisation;
$CRMDC = $CRMCol.Doc_Category;
$spFile = $web.GetFile($CRMOrg);
$termValue = $CRMDC;
$term = $termset.Terms[$termValue];
$itemValue = $spFile.items;
#SetFieldValue function is used to update taxonomy field
$taxField.SetFieldValue($itemValue,$term);
$itemValue.SystemUpdate();
}
write-host -ForegroundColor Green "Disposing the web Object..";
$web.Dispose();