1

I am able to get the date of the last modified item in the list using the script below:

$SiteURL="https://abc.sharepoint.com/sites/sitename"
$ListName="Documents"

Connect-PnPOnline -Url $SiteURL -Credentials (Get Credentials)

(Get-PnPList -Identity $ListName).LastItemUserModifiedDate

Please help me with getting the Item ID of the above last modified item.

Avshalom
  • 8,657
  • 1
  • 25
  • 43
sk5991
  • 45
  • 6

1 Answers1

0

Order by Modified field with desc order and get the first item of the returned items collection:

$SiteURL= "https://Tenant.sharepoint.com/"
$ListName = "Documents"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
#Define Query to Filter
$Query= "<View Scope='RecursiveAll'>
            <Query>
                <Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where>
                <OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>
                </Query>
        </View>"
 
$ListItems = Get-PnPListItem -List $ListName -Query $Query

Write-host "Last Modified Item Id:"$ListItems[0].Id
Jerry
  • 3,480
  • 1
  • 10
  • 12