Is there a way we can get pull list of Items from a View using sharepoint endpoint?

arun pandiyan 0 Reputation points
2024-11-25T19:29:13.4766667+00:00

I have a list in sharepoint and I have created multiple view inside that list.

Is there a way we can pull items from View instead of entire list?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,117 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 48,176 Reputation points Microsoft Vendor
    2024-11-26T09:34:39.9066667+00:00

    You could pull items from a specific view instead of entire list through PNP PowerShell.

    Here are steps:

    1.Grant access by using SharePoint App-Only.

    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs

    2.Run following PNP PowerShell.

    #Config Parameter  
    $SiteURL = "https://tenant.sharepoint.com/sites/AmyTeam"
    $ClientID = "ClientID"
    $ListName = "listname"
    $ViewName= "viewname"
    $SelectedFields = @("ID","Title","test") #InternalName of the selected fields  
    $CSVPath = "C:\ListData.csv"  
    $ListDataCollection= @()  
       
    #Connect to SharePoint Online site
    Connect-PnPOnline -Url $SiteURL -Interactive -ClientId $ClientID
    $Counter = 0
    $List =  Get-PnPList -Identity $ListName  
    $ListView  = Get-PnPView -List $ListName -Identity $ViewName -Includes ListViewXml
    $ListItems = Get-PnPListItem -List $ListName -Query $ListView.ListViewXml
        
    $ListItems | ForEach-Object { 
            $ListItem  = Get-PnPProperty -ClientObject $_ -Property FieldValuesAsText   
            $ListRow = New-Object PSObject  
            $Counter++  
            ForEach($Field in $SelectedFields)   
            {  
                $ListRow | Add-Member -MemberType NoteProperty $Field $ListItem[$Field]  
            }  
            Write-Progress -PercentComplete ($Counter / $($ListItems.Count)  * 100) -Activity "Exporting List Items..." -Status  "Exporting Item $Counter of $($ListItems.Count)"  
            $ListDataCollection += $ListRow  
    }  
    #Export the result Array to CSV file  
    $ListDataCollection | Export-CSV $CSVPath -NoTypeInformation
    

    3.Result:

    User's image

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.