CAML Query with DateTime Filter in PowerShell

Markus Kolbeck
Markus' Blog
Published in
1 min readMay 8, 2017

Querying SharePoint List items with PowerShell is quite easy.

But sometimes you need to set custom (dynamic) filter values that can make things complicated.

In this example I demonstrate how to query SharePoint list items with CAML query and filter out all items that have been modified within the last hour. The challenge was to format the datetime value so that the CAML query accepted the values.

Here is the solution:

[microsoft.sharepoint.utilities.sputility]::CreateISO8601DateTimeFromSystemDateTime($oneHourAgo)

One other thing important to know is that you will have to include the following property in your query:

IncludeTimeValue=”True”

And here is a script example:

Please note that I included another filter in the CAML query for the “Some_Status” column in this example that has the value “Created”.

--

--