0

I must retrieve the name of the user that did the last modification in a given web, using a Power Shell script.

I know that retrieving the last item modification date is straightforward, but how to retrieve the user that did such modification?

Retrieving the last modified item in the web would be fine too, since I would then pick the value of the Modified By field.

1
  • Not sure about user, but you can get the last item modified date by calling siteUrl/_api/web on your browser and search for LastItemModifiedDate property. Commented Jul 9, 2019 at 12:46

2 Answers 2

0

Ciro, we do not have the lastModifiedBy property for spfile. The workaround I can think of is to get the LastModifiedDate first with SPWeb.LastItemModifiedDate. And use the date to set a time filter. Query all files in your site and find the file last modified.

Reference:http://www.sharepointdiary.com/2012/09/find-all-documents-created-modified-by-specific-users-datetime.html

I set the dateFilter to last one day. You can set it to be the time period right before the last item modified date.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Set the date Filter
$dateFilter = (Get-Date).AddDays(-1) #Past One Day
"File, Created Time, File Size" | out-file NewDocuments.csv

# Get all Webs
$webs = Get-SPWebApplication "http://sp19" | Get-SPSite -Limit All | Get-SPWeb -Limit All

#Iterate through webs
ForEach ($web in $webs)
{
   #Iterate through All Lists
    ForEach ($list in $web.Lists)
 {
  #Check for Document Libraries 
        If ($list.BaseType -eq "DocumentLibrary")
  {
     #Iterate through All documents
                   ForEach ($item in $list.Items)
   {
                  If ($item.URL.StartsWith("_")) {Break} #Skip _catalogs, etc
                  If ($item.URL.EndsWith(".aspx")) {Break} #Skip Form pages
                    If ($item.File.TimeLastModified -ge $dateFilter)
    {
                      $result = """$($web.URL)/$($item.URL)"", $($item.File.TimeCreated), $( [Math]::Round($item.File.Length/1024,2))"
                      $result 
                 }
                }
        }
    }
}
0

Last Modified By is saved internally as a string in the "Editor" column.

$webUrl = "https://intranet.engineerer.ch" 
$libName = "Documents" 
$web = Get-SPWeb -Identity $webUrl 
$lib = $web.Lists[$libName] 
$items = $lib.Items 
foreach($item in $items){
    $lastModifiedBy = New-Object Microsoft.SharePoint.SPFieldUserValue($web,$item["Editor"]) 
}

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.