param(
[string]$siteCollUrl = "http://test/sites/site1/", [string]$listTitle = "Stockage",
[boolean]$checkin = $false, [boolean]$publish = $false, [boolean]$deleteAllVersion = $true
)
$web = Get-SPWeb $siteCollUrl
$splList = $web.Lists[$listTitle]
$spqQuery = New-Object Microsoft.SharePoint.SPQuery
$spqQuery.Query = "1 ";
$spqQuery.ViewAttributes = "Scope=""RecursiveAll""";
$spqQuery.ViewFields = " " #_UIVersionString
$spqQuery.ViewFieldsOnly = $true
$spqQuery.RowLimit = 1000;
# IsCheckedoutToLocal
$iNumber = 1
do {
if ($iNumber -eq 1) {
$spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition;
}
$splListItems = $splList.GetItems($spqQuery)
writeInfo "page number : $($iNumber)"
foreach ($splListItem in $splListItems) {
writeInfo "web $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id) # $($splListItem.Name) Title: $($splListItem["Title"]) Version: $($splListItem["owshiddenversion"]) _Level: $($splListItem["_Level"]) _IsCurrentVersion: $($splListItem["_IsCurrentVersion"]) _UIVersion: $($splListItem["_UIVersion"]) ver count : $($splListItem.File.Versions.Count)"
#check in file
try {
if ($checkin) {
$splListItem.File.CheckIn("CheckIn as admin");
}
}
catch {
WriteError "error CheckIn web $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id) "
}
#publish file
try {
if ($publish) {
$splListItem.File.Publish("Publish as admin");
}
}
catch {
WriteError "error Publish web $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id) "
}
#this is a folder
if ($splListItem.ContentTypeId.ToString() -eq "0x00C2208B8CE6E1422CADC1C521EAB2A68B") {
writeInfo "folder file $($splListItem.File.ServerRelativeUrl)"
continue
}
#delete old versions
if ($deleteAllVersion -and $splListItem.File -ne $null -and $splListItem.File.Versions -ne $null -and $splListItem.File.Versions.Count -gt 1) {
$splListItem.File.Versions.DeleteAll();
writeInfo "versions deleted for $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id)"
}
}
$iNumber += 1
$spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition;
}while ($spqQuery.ListItemCollectionPosition -ne $null)
$web.Dispose()
Powershell Paged Caml Query
In Powershell