Find All Documents Created or Modified by a Particular User in Specific Date Time

Requirement is to find all documents which are uploaded to the SharePoint environment during the past one Month. PowerShell can do the reporting well. Lets see the code:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

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

# Get all Webs
$webs = Get-SPWebApplication "https://sharepoint.crescent.com" | 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.TimeCreated -ge $dateFilter) 
				{
					$result = """$($web.URL)/$($item.URL)"", $($item.File.TimeCreated), $( [Math]::Round($item.File.Length/1024,2))"
					$result | Out-File NewDocuments.csv -Append
				}
			}
		}
	}
}

Same way, we can find all documents uploaded to SharePoint sites based on Date criteria by just checking $item.File.TimeLastModified property. Say For instance,

  • You may be interested to see all old documents created an year back 
  • All documents which are not changed during the past one year.

Find All Documents Created or Modified by a Particular User:

In another situation, the request is to find all documents either created by  modified by a particular user in SharePoint 2007.

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets
Function global:Get-SPWebApplication($WebAppURL)
{ 
 if($WebAppURL -eq $null)  #Get All Web Applications
    {
  #Sharepoint 2007 powershell spfarm
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
  $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
  $WebApps = @()
  foreach ($websvc in $websvcs) {
      foreach ($WebApp in $websvc.WebApplications) {
          $WebApps += $WebApp
      }
  }
  return $WebApps
 }
  else #Get Web Application for given URL
 {
    return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
  }
 }
 
Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )
 
   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}

Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion


# Set the date Filter
"File Name `t Created By `t Modified By `t Created `t Last Modified `t File Size `t URL" | out-file AllDocsByUser.csv
 
# Get the Web Application 
$WebApp = Get-SPWebApplication "https://sharepoint.company.com"

#Iterate through site collections
ForEach ($site in $WebApp.Sites)
    {
     #Iterate through webs
     ForEach ($web in $site.AllWebs)
        {
            #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.Author -like "*domain\user*") -or ($item.File.ModifiedBy -like "*domain\user*"))
                           {
                             $result = "$($item.File.Name) `t $($item.File.Author) `t $($item.File.ModifiedBy) `t $($item.File.TimeCreated) `t $($item.File.TimeLastModified) `t  $( [Math]::Round($item.File.Length/1024,2)) `t $($web.URL)/$($item.URL)"
                              $result | Out-File AllDocsByUser.csv -Append
                           }
                     }
                }
           }
      }
  }

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “Find All Documents Created or Modified by a Particular User in Specific Date Time

  • i need a PowerShell script to Move Sharepoint Onpremises Document Library from one site to another site, only with the mandatory dated files and Folders should only to be transfered like from 01-01-2009 to 31-12-2009, suggest me the solution please.

    Reply
  • Hello I am new to SharePoint I tried this in SharePoint 2013 environment it errored out would you please help.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *