0

I am trying to use PnP with CAML Query to retrieve all items in a document library where certain fields meet certain values. The query filter is working fine, it retrieves the correct documents, however I can't seem to get the ViewFields working. All it ever shows me no matter what is the Id, Title, GUID.

$listItems = Get-PnPListItem -List Documents -Query "<view><query>
<ViewFields>
  <FieldRef Name='MyChoice' />
  <FieldRef Name='FileRef' />
  <FieldRef Name='FileLeafRef' />
</ViewFields>
<QueryOptions>
  <ViewAttributes Scope='RecursiveAll' />
  <Lists ServerTemplate='101' />
</QueryOptions>
<Where>
  <And>
           <Eq>
              <FieldRef Name='MyChoice' />
              <Value Type='MultiChoice'>Text Two</Value>
           </Eq>
           <Eq>
              <FieldRef Name='MySecurity' />
              <Value Type='MultiChoice'>Internal</Value>
           </Eq>
  </And>
</Where>
</Query>
</View>"

What am I doing wrong??

1
  • Tested and working with this query $Query = "<View Scope='RecursiveAll'><RowLimit>300</RowLimit> <ViewFields><FieldRef Name='Title'/><FieldRef Name='URL'/></ViewFields> <Query><Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>Process Link</Value></Eq></Where></Query></View>" #get all list items using powershell sharepoint online - matching given query $ListItems = Get-PnPListItem -List $ListName -Query $Query
    – Anuja
    Nov 2, 2020 at 0:09

1 Answer 1

0

When you are looking at the results you get back from Get-PnPListItem, if you do this:

$listItems | ForEach-Object {
$_ | Format-Table;
}

Then it will only show you id, Title and GUID. However, if you do this:

$listItems | ForEach-Object {
$_.FieldValues | Format-Table;
}

You will see that all of the requested field values are actually being returned. So in your case

$_['MyChoice']

should return

Text Two

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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