I have the following powershell which I use to loop through a wiki page library inside my On-Premise site, and filter out all the wiki pages which have been modified after a certain date:

$startdate = Get-Date -Day 05 -Month 03 -Year 2018 -Hour 16 -Minute 00 
$startDateIsoFormat = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime($startdate)
$emailbody =""
$web = Get-SPWeb "http://****/kb/info"
$userfriendlyURL  = "http://www.*****.intra/kb/info"
$list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Pages"))  
$spQuery = New-Object Microsoft.SharePoint.SPQuery;
$camlQuery = "<Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'>$startDateIsoFormat</Value></Geq></Where>";
$spQuery.Query = $camlQuery
$listItems = $list.GetItems($spQuery)

foreach ($item in $listItems)
    $emailbody = $emailbody + '<br/> <a href ="'    + $userfriendlyURL  + '/Pages/' + $item["LinkFilename"].toString() + '">'   + $item["Title"].toString() + '</a>' 
    Write-Host "found" 

Now, I want the same powershell script to run against a SharePoint Online site using PNP script, but I am not sure which commands I need to change and if I can run CAML queries against SP online libraries?

1 Answer 1


You need to use Connect-PnPOnline to connect to your site and then use the Get-PnPListItem command with Query parameter to get the filtered list items as below:

Connect-PnPOnline -Url "https://your-tenant.sharepoint.com/sites/test" -UseWebLogin

$filterDate = Get-Date -Day 05 -Month 03 -Year 2018 -Hour 16 -Minute 00
$formattedDate = $filterDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")

$caml = "<View><Query><Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'>$formattedDate</Value></Geq></Where></Query></View>"

$items = Get-PnPListItem -List "Pages" -Query $caml

foreach ($i in $items) {
    #do some stuff here 

You need to use the PnP SharePoint online PowerShell.

You can download it from here

Your Answer

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

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