How to update managed metadata column for all file in document library using powershell

Hi,

How to update managed metadata column for all file in document library using powershell?

Any help on it.

Thanks & REgards

Poomani Sankaran

March 18th, 2015 6:06am

Will all of the items in the library have the same metadata tag?
Free Windows Admin Tool Kit Click here and download it now
March 18th, 2015 6:57am

Hi TenPart,

Yes..  In the document library i have created many folders and sub folders with files.

But all the files in same meta data tag only. I need to change from one to another.

March 18th, 2015 7:02am

$web = Get-SPWeb http://portal.sharepoint.com
$list = $web.Lists["LargeList"]

$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000
$caml = '<Where><BeginsWith><FieldRef Name="Title" /><Value Type="Text">Item 1</Value></BeginsWith></Where>' +
        '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>' 
$query.Query = $caml 

do
{
    $listItems = $list.GetItems($query)
    $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    
    foreach($item in $listItems)
    {
        #Cast to SPListItem to avoid ambiguous overload error
        $spItem = [Microsoft.SharePoint.SPListItem]$item;
        
        #Get the taxonomy field for the list item
        $taxField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$spItem.Fields["Project"]
        
        #Set the field's value using the term
        $taxField.SetFieldValue($spItem,$term)
        $spItem.Update()
    }
}
while ($spQuery.ListItemCollectionPosition -ne $null)
This will do what you want. Change it to suit your environment.
Free Windows Admin Tool Kit Click here and download it now
March 18th, 2015 7:56am

Hi TanPart,

I have changed the code which you have give in order to get the files from SharePoint 2010 Foundation  Document Library.But i am getting below error in powershell.

Property 'ListItemCollectionPosition' cannot be found on this object; make sure it exists and is settable.

Could you tell me which is the issues in it?

See the code below.

$web = Get-SPWeb http://ntmoss2010:9090/Site
$list = $web.Lists["DocLib"]

$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000
$caml = '<Where><Contains><FieldRef Name="Title" /><Value Type="Text">Process Documents/Delivery</Value></Contains></Where>' +
        '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
$query.Query = $caml

do
{
    $listItems = $list.GetItems($query)
    $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    
    foreach($item in $listItems)
    {
        #Cast to SPListItem to avoid ambiguous overload error
        $spItem = [Microsoft.SharePoint.SPListItem]$item;
        Write-Host $spItem.Title       
    }
}
while ($spQuery.ListItemCollectionPosition -ne $null)

Thanks & Regards

Poomani Sankaran

March 19th, 2015 2:16am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics