how to get the report for recent uploaded files into libraries for a site collection based on date range??

Raki 486 Reputation points
2020-08-25T20:53:54.103+00:00

hi,

how to get a report for last two months recent uploaded files from a site collection? so i have site collection and in that site collection i have multiple libraries. i want to iterate through all the libraries and give me the report for all files which has uploaded last two months basically based on date range using powershell?

Note: this is for sharepoint server 2016

Thanks

Microsoft 365 and Office | SharePoint Server | Development
{count} votes

Accepted answer
  1. Echo Du_MSFT 17,316 Reputation points
    2020-08-27T09:26:57.25+00:00

    Hi raki-3122,

    You could run the following script code in the SharePoint Management Shell as an Admin:
    20768-test.txt

    Thanks,
    Echo Du

    ----------

    @Raki
    If the response is helpful, please click "Accept Answer" and upvote it


1 additional answer

Sort by: Most helpful
  1. sadomovalex 3,636 Reputation points
    2020-08-27T15:12:52.247+00:00

    hello, you may use SPChangeQuery for that:

    var now = DateTime.Now;
    foreach (SPList in web.Lists)
    {
        var start = now.AddMonths(-2);
        var end = now;
        var changeTokenStart = new SPChangeToken(SPChangeCollection.CollectionScope.List, list.ID, start.ToUniversalTime());
        var changeTokenEnd = new SPChangeToken(SPChangeCollection.CollectionScope.List, list.ID, end.ToUniversalTime());
        var changeQuery = new SPChangeQuery(false, false);
        changeQuery.Item = true;
        changeQuery.Add = true;
        changeQuery.Delete = false;
        changeQuery.Update = false;
        changeQuery.ChangeTokenStart = changeTokenStart;
        changeQuery.ChangeTokenEnd = changeTokenEnd;
        changeQuery.FetchLimit = 1000;
        var changes = list.GetChanges(changeQuery);
    
        foreach (SPChangeItem c in changes)
        {
            SPListItem item = null;
            try
            {
                item = list.GetItemById(c.Id);
            }
            catch (Exception x)
            {
                // handle error
                continue;
            }
    
            // when folder is added item.File is null
            if (item == null || item.File == null)
            {
                continue;
            }
            Console.WriteLine(item.File.Name);
        }
    }
    
    0 comments No comments

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.