private775 icon

[PS] SharePoint - Approve all items in the list

private775 | PRO | 09/14/18 10:29:22 AM UTC | 0 ⭐ | 578 👁️ | Never ⏰ | []
PowerShell |

700 B

|

None

|

0 👍

/

0 👎

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
 
$webUrl = "http://acme.local/site/ss/"
$listtName = "Some List"
 
$w = get-spweb $webUrl
$l = $w.Lists.TryGetList($listtName)
 
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = 4900
$caml = "<Where><Neq><FieldRef Name='_ModerationStatus'/><Value Type='ModStat'>0</Value></Neq></Where>"
$spQuery.Query = $caml 
 
$ii = $l.GetItems($spQuery)
 
$ii | % {
    $i = $_
    if($i.ModerationInformation -ne $null){
        $i.ModerationInformation.Status = [Microsoft.SharePoint.SPModerationStatusType]::Approved
        $i.ModerationInformation.Comment = 'Automatically Approved'
        $i.Update()
    }
}

Comments