2

I am trying to update a managed metadata field but I get an error saying `Property 'ListItemCollectionPosition' cannot be found on this object'$spQuery.<<

$site1 = Get-SPSite mysite

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy")
$site2 = $site1
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site2)
$termStore = $session.TermStores["Managed Metadata Service"]
$group = $termStore.Groups["mygroup"]
$termSet = $group.TermSets[mytermset"]
$terms = $termSet.GetTerms(100)
$term = $terms | ?{$_.Name -eq "Off"}

$web1 = Get-SPWeb myweb
$list1 = "Board meetings"
$list2 = $web1.Lists[$list1]


if($list2.BaseType -eq "DocumentLibrary")
{ 

 $Count = $List.Folders.Count + $list.Items.Count    
 if($list2.Fields.ContainsField("marking") -eq $true)
 {
   $query = New-Object Microsoft.SharePoint.SPQuery
   $query.ViewAttributes = "Scope='Recursive'";
   $query.RowLimit = 2000
   $caml = '<Where><AND><Neq><FieldRef Name="marking" /><Value Type="Text">Off-S</Value></Neq><Neq><FieldRef Name="marking" /><Value Type="Text">Off-S</Value></Neq></AND></Where>' +

   $query.Query = $caml

  do
  {
   $listItems = $list2.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["GPMS marking"]

    $taxField.SetFieldValue($spItem,$term)
    $spItem.SystemUpdate()
   }
  }
   while ($spQuery.ListItemCollectionPosition -ne $null)
 }
}
1

You are creating a an SPQuery object with name $query

$query = New-Object Microsoft.SharePoint.SPQuery

But then you are using $spQuery.ListItemCollectionPosition. Change it to $query.ListItemCollectionPosition Also change while ($spQuery.ListItemCollectionPosition -ne $null) to while ($query.ListItemCollectionPosition -ne $null)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.