Quantcast
Channel: Second Life of a Hungarian SharePoint Geek
Viewing all articles
Browse latest Browse all 206

Approving all pending documents (and folders) of a specified library using PowerShell

$
0
0

Last week I wrote already about querying documents based on their moderation status. This time my goal was to approve all pending documents in a specified document library. I found a similar PowerShell script, but it does not handle approval of folders, so I created my own version displayed below:

$site = Get-SPSite("http://yourserver.com")
$web = $site.OpenWeb("/yourweb")

function approveItems($list) 
{
  Write-Host Processing $list
  $query = New-Object Microsoft.SharePoint.SPQuery
  $query.Query = "<Where><Eq><FieldRef Name=’_ModerationStatus’ /><Value Type=’ModStat’>2</Value></Eq></Where>"
  $query.ViewAttributes = "Scope = ‘RecursiveAll’"
  $items = $list.GetItems($query)

  $items | % {
    Write-Host Approving:  $_["Name"]
    $_["_ModerationStatus"] = 0
    $_.Update()
  }

  Write-Host —————————
}

approveItems $web.Lists["YourList"]

As you can see, the key is the usage of RecursiveAll scope in ViewAttributes that include recursively both folders and documents. If you would like to approve all documents on your site, you need something like this:

$web.Lists | % { approveItems $_ }



Viewing all articles
Browse latest Browse all 206

Trending Articles