Created
June 11, 2013 20:28
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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.... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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