Skip to content

Instantly share code, notes, and snippets.

@nlarkin
Created June 11, 2013 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlarkin/5760348 to your computer and use it in GitHub Desktop.
Save nlarkin/5760348 to your computer and use it in GitHub Desktop.
Powershell SPQuery to get documents created / modified within a specified time period (1 day in this case).
#Get SPWeb and Our List we are targeting.
$web = Get-SPWeb "http://spweburl"
$list = $web.Lists["List Name"]
#Build Query
$spQuery = New-Object Microsoft.SharePoint.SPQuery
#CAML Query Using a DateTime Value and and Offset of Today
$query = '<Where><Geq><FieldRef Name="Last_x0020_Modified" /><Value Type="DateTime"><Today OffsetDays="-1" /></Value></Geq></Where>'
$spQuery.ViewAttributes = "Scope = 'Recursive'"
$spQuery.Query = $query
$spQuery.RowLimit = $list.ItemCount
$spListItemCol = $list.GetItems($spQuery)
#Do Something with our ListItemCollection
foreach ($item in $spListItemCol)
{
#CODE HERE....
}
@andreasblueher
Copy link

I would recommend to not use "$list.ItemCount" since with more than 5000 modified items within the last day you would run into an exception. Else thanks for this example, helped me a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment