# Find all files on SharePoint Online between two dates

**URL:** <https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896>\
**Category:** PowerShell Help\
**Created:** [September 18, 2023, 9:37pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896 "2023-09-18T21:37:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 18, 2023, 9:37pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/1 "2023-09-18T21:37:06Z")

</div>

I am trying to write a script in PowerShell that copies all my files from one site to another site. I am trying to keep costs down by only taking so many files at the same time. I figured I would do this with a date range on Created Date. But I cannot get it to use date to filter the list nor can it get it to sort the list by Created. Here is what I have tried:

```auto
Get-PnPListItem -List $ListName -PageSize 500 | Where-object {$_.FieldValue.Created -GT [DateTime]'02/16/2015'} 
    
Get-PnPListItem -List $ListName -PageSize 500 | where-object {($_.FileSystemObjectType -eq "File" -and $_.Created -gt [DateTime]'02/16/2015')} 
    
Get-PnPListItem -List $ListName -PageSize 500 | where-object { $_.FileSystemObjectType -eq "File" -and $_['Created_x0020_Date'] -gt $Created } 
    
$ListItems = $ListItems | Sort $_.Created # also tried $_['Created_x0020_Date']

```

If I use a CAML query I always get the exceed the list view threshold error even with defined in the query.

```auto
    $Query = 
    "<View>
    <RowLimit Paged = 'TRUE'>100
    <Query>
    <Where>
    <And>
    <Geq>
    <FieldRef Name='Created' />
    <Value Type='DateTime'>2015-01-01T12:00:00Z</Value>
    </Geq>
    <Leq>
    <FieldRef Name='Created' />
    <Value Type='DateTime'>2015-01-30T12:00:00Z</Value>
    </Leq>
    </And>
    </Where>
    </Query>    
    </RowLimit>
    </View>";

     Get-PnPListItem -List $ListName -PageSize 500 -Query $Query

```

Can anyone help me figure this out?

> <https://stackoverflow.com/questions/77114869/find-all-files-on-sharepoint-online-between-two-dates>

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 18, 2023, 9:48pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/2 "2023-09-18T21:48:36Z")

</div>

Joe,  
Welcome to the forum. 👋🏼

I have no experiences with SharePoint. But if the propertys name is really `Created` this should do the trick to get it sorted:

```auto
$ListItems |
    Sort-Object -Property Created

```

Once you have the property `Created` as direct property and once as sub property of the property `FieldValue`. What’s the correct one? And are you actually sure the name of the property is `Created` and that it is of the type `[DateTime]`?

What’s the output of

```auto
Get-PnPListItem -List $ListName -PageSize 500 | 
    Get-Member -Name *created*

```

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 12:58pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/3 "2023-09-19T12:58:24Z")

</div>

Olaf,  
I tried your Get-Member on created and modified and neither of them returned anything I suspect that is because they are in a subfield called FieldValues so that is why you see FieldValues. Created. The idea for the uses of these is from multiple website examples. If I -expandproperty on FieldValues it is listed on the output. I guess I was hoping there was something obviously wrong with my code.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 3:20pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/4 "2023-09-19T15:20:53Z")

</div>

> [@YosiP](#):
>
> If I -expandproperty on FieldValues it is listed on the output.

And what is the output of that? Do you still need help or have you solved your issue already?

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 3:36pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/5 "2023-09-19T15:36:00Z")

</div>

@Olaf  
I am sorry who do I do get-member on a field in a subfield?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 4:58pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/6 "2023-09-19T16:58:01Z")

</div>

> [@YosiP](#):
>
> I am sorry who do I do get-member on a field in a subfield?

You mentioned …

> [@YosiP](#):
>
> If I -expandproperty on FieldValues it is listed on the output.

So you pipe this output to `Select-Object` and provide the subproperty name … `Created` seemingly.

```auto
.... |
Select-Object -ExpandProperty FieldValues |
    Select-Object -Property Created |
        Get-Member

```

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 5:20pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/7 "2023-09-19T17:20:07Z")

</div>

TypeName: Selected.System.Collections.Generic.Dictionary`2[System.String,System.Object]

Name MemberType Definition

* * *

Equals Method bool Equals(System.Object obj)  
GetHashCode Method int GetHashCode()  
GetType Method type GetType()  
ToString Method string ToString()  
Created NoteProperty object Created=null

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 5:29pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/8 "2023-09-19T17:29:33Z")

</div>

here is proof that it is populated  
Created 12/8/2014 2:32:08 PM

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 5:44pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/9 "2023-09-19T17:44:05Z")

</div>

Please format your code, error messages AND CONSOLE OUTPUT as code.

Hhhhmmm … looks like it is a hashtable with a string in it. What’s the output of …

```auto
.... |
Select-Object -ExpandProperty FieldValues |
    Select-Object -Property Created |
        Select-Object -Property Created

```

?

… formatted as code please! ☝🏼

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 5:57pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/10 "2023-09-19T17:57:02Z")

</div>

I used -expandproperty and this is what I got as part of the results  
Created 12/8/2014 2:32:08 PM  
But if I use your code

```auto
.... |
Select-Object -ExpandProperty FieldValues |
    Select-Object -Property Created |
        Select-Object -Property Created
Then I get this: 
Created
--------

```

* * *

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 6:10pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/11 "2023-09-19T18:10:01Z")

</div>

> [@YosiP](#):
>
> ```auto
> Then I get this: 
> Created
> --------
> 
> ```

That’s all? Nothing underneath the “`--------`”?

OK, what’s the output of …

```auto
.... |
Select-Object -ExpandProperty FieldValues |
    Select-Object -ExpandProperty Created 

```

?

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 6:24pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/12 "2023-09-19T18:24:30Z")

</div>

```auto
 Get-PnPListItem -List 'Documents' -Id 4722 |
 Select-Object -ExpandProperty FieldValues | 
    Select-Object -ExpandProperty Created 
Select-Object : Property "Created" cannot be found.
At line:3 char:5
+ Select-Object -ExpandProperty Created
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (System.Collecti...,System.Object]:PSObject) [Select-Object], PSArgumentException
    + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

```

It takes to long to do the whole list so I just picked one id out and ran it on that. And like I said if I just do this:

```auto
Get-PnPListItem -List 'Documents' -Id 4722 |
 Select-Object -ExpandProperty FieldValues

```

I get this, it of course is just part of the results

```auto
Modified 12/8/2014 2:32:09 PM                                                                                                                    
MediaServiceGenerationTime                                                                                                                                               
MediaServiceEventHashCode                                                                                                                                                
Created 12/8/2014 2:32:08 PM                                                                                                                    
_ExtendedDescription                                                                                                                                                     
TriggerFlowInfo                                                                                                                                                          
MediaServiceImageTags {}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 6:30pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/13 "2023-09-19T18:30:40Z")

</div>

> [@YosiP](#):
>
> It takes to long to do the whole list …

You should save this list in a variable. So you don’t have to run the query again and again.

> [@YosiP](#):
>
> so I just picked one id out

And you can still do that on the list coming from a variable.

The output of …

```auto
Get-PnPListItem -List 'Documents' -Id 4722 |
    Select-Object -ExpandProperty FieldValues |
        Select-Object -ExpandProperty Created

```

Should be only the date, right?

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 19, 2023, 6:32pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/14 "2023-09-19T18:32:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/6/64b8338a7435dca5ae03b6de48a1a441aff78dbf.png)  
if I do this query I get nothing as you can see there is a file with a great tan date of 01/01/2015 I get nothing back.

```
Get-PnPListItem -List 'Documents' -id 29970 | Where {$_.FieldValue.Created -ge '01/01/2015'} ;$listItems.count

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 7:02pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/15 "2023-09-19T19:02:32Z")

</div>

> [@YosiP](#):
>
> if I do this query I get nothing as you can see there is a file with a great tan date of 01/01/2015

If the type you get back from this query is not of `[DateTime]` you have to convert it before you can compare it to a `[DateTime]`.

If you already saved your complete list in the variable `$ListItems` you may try this:

```auto
$Limit = Get-Date -Day 1 -Month 1 -Year 2015

$ListItems | | 
    Where-Object {
        ([datetime]::ParseExact($_.FieldValue.Created,'M/d/yyyy h:m:s tt',[System.Globalization.CultureInfo]::GetCultureInfo('en-US'))) -lt $Limit
    } 

```

This should give you all documents _ **before** _ the 1st of January 2015.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [September 19, 2023, 9:49pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/16 "2023-09-19T21:49:35Z")

</div>

It is a datetime. Fieldvalues is a dictionary. I haven’t figured out the silly camel query yet, but this should get YosiP going without it.

```auto
Get-PnPListItem -List $ListName -PageSize 500 | Where-Object {
    $_.fieldvalues['Created'] -gt [DateTime]'01/01/2015' -and
    $_.fieldvalues['Created'] -lt [DateTime]'01/31/2015'
}

```

You can even omit the cast to datetime since the LHS is a datetime

```auto
Get-PnPListItem -List $ListName -PageSize 500 | Where-Object {
    $_.fieldvalues['Created'] -ge '01/01/2015' -and
    $_.fieldvalues['Created'] -le '01/31/2015'
}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 9:56pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/17 "2023-09-19T21:56:25Z")

</div>

> [@krzydoug](#):
>
> It is a datetime. Fieldvalues is a dictionary.

Why be simple when you can do it the hard way? 🤷🏼‍♂️ 🙄

Sometimes I wonder if MSFT programers do those stuff on purpose. 😏

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 19, 2023, 10:12pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/18 "2023-09-19T22:12:42Z")

</div>

> [@krzydoug](#):
>
> ```auto
> Get-PnPListItem -List $ListName -PageSize 500 | where-object {
> $_.fieldvalues['Created'] -gt '01/01/2015' -and
> $_.fieldvalues['Created'] -gt '01/31/2015'
> }
> 
> ```

Shouldn’t the second comparison operator be `-lt` or `-le`? 😉

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [September 19, 2023, 10:58pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/19 "2023-09-19T22:58:16Z")

</div>

Copy pasta fail - thanks for always having my back Olaf.

---

<div class="post-metadata">

**Author:** ![YosiP](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@YosiP](https://forums.powershell.org/u/YosiP)\
**Post date:** [September 20, 2023, 12:48pm UTC](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896/20 "2023-09-20T12:48:08Z")

</div>

What do you mean by “dictionary”?

[Next page](https://forums.powershell.org/t/find-all-files-on-sharepoint-online-between-two-dates/22896.md?page=2)
