Sep 20 2023 12:28 AM
Hi. I want to filter a Site Page library by SharePoint Rest Api in PowerShell. I made script like this
Sep 20 2023 02:21 AM
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
Sep 20 2023 02:28 AM
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:
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