Skip to main content

this code working for caml query with powershell 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

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 = "<Where><Neq><FieldRef Name='_Level' /><Value Type='Number'>1</Value></Neq></Where><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>"; 

$spqQuery.ViewAttributes = "Scope=""RecursiveAll""";
$spqQuery.ViewFields = "<FieldRef Name='FileLeafRef' /><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='owshiddenversion' /><FieldRef Name='_Level' /><FieldRef Name='_IsCurrentVersion' /><FieldRef Name='_UIVersion' />" #_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) 
    { 
        #do your job
    }
    $iNumber+=1 
    $spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition;
}
while($spqQuery.ListItemCollectionPosition -ne $null) 

$web.Dispose()

do{ if($iNumber -eq 1) { $spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition; } $splListItems = $splList.GetItems($spqQuery) writeInfo "page number : $($iNumber)" foreach ($splListItem in $splListItems) { #do your job } $iNumber+=1 $spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition; }while($spqQuery.ListItemCollectionPosition -ne $null)

$web.Dispose()

get script here

this code working for caml query with powershell 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) { #do your job } $iNumber+=1 $spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition; }while($spqQuery.ListItemCollectionPosition -ne $null)

$web.Dispose()

get script here

this code working for caml query with powershell

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 = "<Where><Neq><FieldRef Name='_Level' /><Value Type='Number'>1</Value></Neq></Where><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>"; 

$spqQuery.ViewAttributes = "Scope=""RecursiveAll""";
$spqQuery.ViewFields = "<FieldRef Name='FileLeafRef' /><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='owshiddenversion' /><FieldRef Name='_Level' /><FieldRef Name='_IsCurrentVersion' /><FieldRef Name='_UIVersion' />" #_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) 
    { 
        #do your job
    }
    $iNumber+=1 
    $spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition;
}
while($spqQuery.ListItemCollectionPosition -ne $null) 

$web.Dispose()

get script here

Source Link

this code working for caml query with powershell 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) { #do your job } $iNumber+=1 $spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition; }while($spqQuery.ListItemCollectionPosition -ne $null)

$web.Dispose()

get script here