Forum Discussion
Rest API filter by two and more columns
Hi. I want to filter a Site Page library by SharePoint Rest Api in PowerShell. I made script like this
- SvenSieverdingBronze Contributor
Hi buszi99
It works if you use "and" instead of "&&"$URL = "/_api/web/lists/GetByTitle('$varList')/items?`$select=Title,Modified,ContentType,ID,Created&`$filter=ContentType eq 'Site Page' and Modified lt '2023-06-09'"
Best Regards,
Sven - LeonPavesicSilver Contributor
Hi buszi99,
To filter a Site Page library by SharePoint Rest Api in PowerShell by two and more columns, you can use the following steps:
- Create a new PowerShell script.
- Import the SharePoint PnP PowerShell module.
- Connect to your SharePoint site using the Connect-PnPOnline cmdlet.
- Create a variable for the Site Page library name.
- Create a variable for the REST API URL. The URL should include the following parameters:
- $select: This parameter specifies the fields that you want to return in the response.
- $filter: This parameter specifies the filter criteria that you want to use.
- Use the Invoke-PnPSPRestMethod cmdlet to call the REST API and retrieve the Site Page items.
- Save the script and run it.
Here is an example of a PowerShell script that filters a Site Page library by Last Modified Date and Content Type:
# Import the SharePoint PnP PowerShell module. Import-Module SharePointPnPPowerShellOnline # Connect to your SharePoint site. Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/teamsite" # Create a variable for the Site Page library name. $varList = "Site Pages" # Create a variable for the REST API URL. $URL = "/_api/web/lists/GetByTitle('$varList')/items?`$select=Title,Modified,ContentType,ECCKAssetID,ID,Created&`$filter=ContentType eq 'Site Page' && Modified le '2023-06-09'" # Use the Invoke-PnPSPRestMethod cmdlet to call the REST API and retrieve the Site Page items. $items = Invoke-PnPSPRestMethod -Method Get -Url $URL -ContentType "application/json;odata=verbose" # Display the Site Page items. foreach ($item in $items) { Write-Host "$($item.Title) - $($item.Modified)" }
I recommend using SharePoint online Management Shell opened in elevated mode (as administrator):
Download SharePoint Online Management Shell from Official Microsoft Download Center
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic