Find all files on SharePoint Online between two dates

Trying this code now

As I am the over-cautious type how would I do a select on created? So I can do a spot check on the files. I can’t for the life of me find out how to actually get only the dates I want in the actual SharePoint website. You would think Microsoft would be better at these things.
Select -First 1 $_.fieldvalues['Created']
I tried the above and get Can’t index a null value.
Thanks for all your help.

Please share the code you used and the complete error message. Both formatted as code please.
Please keep in mind: We cannot see your screen and we cannot read your mind and we do not have access to your or very likely not even a similar environment to test. :wink:

Sorry I though I did. It even showed up on the preview pane. Here is the codes I have tried and got the same message.

$ListItems | select   $_.fieldvalues['Created']
$ListItems | select   $_['Created']
$ListItems | select   $_.fieldvalues['Modified']
Cannot index into a null array.
At line:2 char:1
+ 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

What I really want is Name of the file, Created Date, and Modified Date.

I am also trying to sort this so that when I do the copy and it gets to the limits that Microsoft sets I can restart it from the same date and know I am getting the correct files. I tried sorting by Created but get the same Cannot index into a null array.

   $listItems =  Get-PnPListItem -List $ListName -PageSize 500 | Where-Object {
    $_.fieldvalues['Created'] -gt [DateTime]'12/01/2014' -and
    $_.fieldvalues['Created'] -lt [DateTime]'12/3/2014' -and $_.FileSystemObjectType -eq "File"
} |  sort $_.fieldvalues['Created'] ;$listItems.count
Cannot index into a null array.
At line:1 char:8
+        $listItems =  Get-PnPListItem -List $ListName -PageSize 500 |  ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

I have the feeling it gets more and more confused.

If this …

… already failes your variable should be empty. And therefor all subsequent queries cannot work. Or did I get something wrong? :thinking:

Why don’t we start with a simple query collecting all documents from this one list?

$DocumentList =  Get-PnPListItem -List $ListName

If that works without an error we should be able to get a count …

$DocumentList.count

Now we try to limit the output to the timeframe of your choice:

$December2014 =
$DocumentList | 
Where-Object {
    $_.fieldvalues['Created'] -gt [DateTime]'12/01/2014' -and
    $_.fieldvalues['Created'] -lt [DateTime]'12/31/2014'
}
$December2014

If that worked you can pick the properties you want to output:

$December2014 |
    Select-Object -Property Name,
        @{Name = 'CreateDate'; Expression = {$_.fieldvalues['Created']}},
        @{Name = 'ModifiedDate'; Expression = {$_.fieldvalues['Modified']}}

And of course we can now use the added properties CreateDate and/or ModifiedDate to sort by it. :wink:

The above did work and now I will try your Select-Object statement. Thank!

YES!!! Thank you! I have been working on this for weeks now. I think the entirety of the code is now ready for a final test before I do the whole site. Thanks Again, Doug and Olaf!

Here is how I verified the dates of the files, it’s similar to select

$DocumentList | 
Where-Object {
    $_.fieldvalues['Created'] -gt [DateTime]'12/01/2014' -and
    $_.fieldvalues['Created'] -lt [DateTime]'12/31/2014'
} | Foreach-Object {
    $_.fieldvalues['Created']
}