Retrieve Modified By propery for items

Tan Phat Huynh 41 Reputation points
2021-08-03T20:51:15.14+00:00

Hello, I have the script below that display Title and Modified date but for the life of me, I could not get it to display Modified By for the items. Thanks in advance.

$SiteURL= read-host 'Enter list site: '#'https://company.sharepoint.com/sites/testsite'
$ListName= read-host 'Enter list name: ' #"test document library"

Connect to PNP Online

Connect-PnPOnline -Url $SiteURL -Credentials $userCredentials

sharepoint online pnp powershell get list items

$ListItems = Get-PnPListItem -List $ListName -Fields "Title"
write-host 'SiteURL ,' 'ListName ,' 'Title ,' 'Modified'

Loop through each Item

foreach($ListItem in $ListItems)
{
#Write-Host "Title:" $ListItem["Title"] $ListItem["Created"]
Write-Host $SiteURL ',' $ListName ',' $ListItem["Title"] ',' $ListItem["Modified"]

}

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. JoyZ 18,111 Reputation points
    2021-08-04T05:58:15.487+00:00

    @Tan Phat Huynh ,

    Use following code to retrieve the "Modified By" property for items:

    $ListItem['Editor'].Email  
    

    Simple test for your reference:

    #Set Variables  
    $SiteURL= "https://tenant.sharepoint.com/sites/Team1"  
    $ListName="lib76"  
        
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
       
    #Get All Files from the document library - In batches of 500  
    $ListItems = Get-PnPListItem -List $ListName -PageSize 500 | Where {$_["FileLeafRef"] -like "*.*"}  
        
    #Loop through all documents  
    $DocumentsData=@()  
    ForEach($Item in $ListItems)  
    {  
        #Collect Documents Data  
        $DocumentsData += New-Object PSObject -Property @{  
        FileName = $Item.FieldValues['FileLeafRef']  
        FileURL = $Item.FieldValues['FileRef']  
        ModifiedBy = $Item.FieldValues['Editor'].Email  
        }  
    }  
    $DocumentsData  
    

    Result:

    120310-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    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.


0 additional answers

Sort by: Most helpful

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.