• I would like to have the report of items modified in last 24 hours from site collection
  • Could anyone suggest me the best approach to hang with it either by going with SPaudit or with SPSiteDataQuery to get detail information and how can i do it.

You can do this with search and PowerShell as follows:

#Use Nuget to to get the latest CSOM dlls.
Add-Type -Path "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Search.dll"
$pass = Read-Host -Prompt "Password:" -AsSecureString
$user = "youruser@some-tenant.onmicrosoft.com"
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user, $pass) 
$url = "https://some-tenant.sharepoint.com"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url) 
$ctx.Credentials = $creds

function Get-SearchResults {
    param (
    $keyWordQry = New-Object Microsoft.SharePoint.Client.Search.Query.KeywordQuery($ctx)
    $keyWordQry.TrimDuplicates = $false
    $keyWordQry.EnableStemming = $false
    $keyWordQry.QueryText = $query
    $searchExec = New-Object Microsoft.SharePoint.Client.Search.Query.SearchExecutor($ctx)
    $results = $searchExec.ExecuteQuery($keyWordQry)
    Write-Output $results
$query = "Write>=" + (Get-date).AddDays(-1).ToString("dd/MM/yyyy")
#This returns a generic list that you can filter to get the results you need.
#In this instance just the path of the modified object is being returned.
$srchRes = Get-SearchResults -query $query 
$srchRes.Value[0].ResultRows | % {$_["Path"]}

This is a basic example to get you started but you should consider paging the search results before you use this regularly. You do that by specifying a startrow and a rowlimit property for the KeywordQuery object.


You can try the following script :

Get-Childitem $dir_to_look -Recurse | where-object {!($_.psiscontainer)} | where { $_.LastWriteTime -gt $month_backdate } | foreach {  Write-Host "$($_.LastWriteTime) :: $($_.Fullname) "  } | export-csv -path \\share\filename.csv


function Get-OldFiles {
 $folders = get-childitem “D:\TestFolder” -recurse | Where-Object {$_.psIsContainer -eq $true}
 foreach ($folder in $folders) {
     $oldfiles = Dir $folder.fullname *.* | where-object {$_.LastWriteTime -le $date}
     if ($oldfiles.count) {
         [float]$totalsize = ($oldfiles | Measure-Object -Sum length).Sum / 1KB
         $data = @{‘Folder’=$folder.fullname;’Count’=$oldfiles.count;’Size(Kb)’=$totalsize}
        New-Object -Type PSObject -Prop $data
Get-OldFiles ’dd/mm/yyyy′ | Export-CSV \\sharename\file.csv -NoTypeInformation

Alternatively, you may try this automated solution which assists you to accomplish this tasks.

  • Find No Luck in both the approach , 2nd option is generating the excel but with no data , Hope you look further in helping me – MSA Jul 4 '17 at 11:15
  • This is not a SharePoint solution. This will only work on a local folder... – Bunzab Jul 4 '17 at 12:27
  • There is a possibility to implement in content search web part or search results web part to show latest modified items. – Nag1987 Jul 4 '17 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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