I have associated a custom content type to a document library and this content type as multiple fields.
The FieldXYZ termset from which this field is derived has 2 values ('Success' , 'Failed').
In my PowerShell script, I am updating a field FieldXYZ value for all documents in the root directory of the library.
The PowerShell code for updating the field is as follows:
$lists = $web.lists
foreach ($list in $lists)
{
if ($list.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)
{
write-host "Document Lib : " , $list.title
SetFieldValuebyGUID($list.RootFolder)
SetFieldValuebyVal($list.RootFolder)
}
}
Function SetFieldValuebyGUID($rootfolder)
{
foreach($docfile in $rootfolder.Files)
{
write-host $docfile.Properties["FieldXYZ"]
$docfile.CheckOut()
$docfile.Properties["FieldXYZ"] = n5f52e7f-bb83-4c01-xxxxxxxxx
$docfile.Update();
$docfile.CheckIn('updated property GUID')
write-host $docfile.Properties["FieldXYZ"]
}
}
Function SetFieldValuebyVal($rootfolder)
{
foreach($docfile in $rootfolder.Files)
{
write-host $docfile.Properties["FieldXYZ"]
$docfile.CheckOut()
$docfile.Properties["FieldXYZ"] = "Success"
$docfile.Update();
$docfile.CheckIn('updated property GUID')
write-host $docfile.Properties["FieldXYZ"]
}
}
The script is not updating the values of the field.
Any ideas on how to resolve the issue?