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?
================ foreach ($item in $list.items) { $item["parametr"] = GUID $item.Update()
}
– Daniel Aug 02 '15 at 04:45CAMLquery on your list to get ListItems from specific folder and then makeforeachthrough ListItemCollection. So make caml query on specific folder you can set SPQuery.Folder property, like showed in the anwer of this post http://sharepoint.stackexchange.com/questions/59216/get-all-files-from-sub-folder-of-a-certain-content-type – ECM4D Aug 02 '15 at 19:12