Using PowerShell to Approve List Items

Home » Miscellaneous » Using PowerShell to Approve List Items

Using PowerShell to Approve List Items

Posted on

During the long and painful process of transferring this blog from SharePoint 2007 to SharePoint 2010, I came across a couple of annoying problems.  Fortunately, the most annoying problem was quite easy to solve. When I copied the old list items over, they showed up in the new list with an approval status of "Pending", preventing them from showing up on the main blog page and in theRSS feed.  Ok, not a big deal, but I’ve got hundreds of blog posts going back several years – I sure wasn’t going to go through and approve everything manually.  This is where PowerShell comes in *real* handy.  A quick script and I was back in business.  Here it is in case you ever find yourself in the same situation:

   

$site = new-object Microsoft.SharePoint.SPSite("http://site")
$web = $site.OpenWeb()
$list = $web.Lists["Posts"]
$items = $list.Items

foreach ($item in $items)
{
    $item["_ModerationStatus"] = 0
    $item.Update()
}

   

Simple but effective.  The script just loops through the target list and sets the Approval Status field (note that the internal name is "_ModerationStatus") to a value of zero, which in SharePoint-speak means "Approved".

I love simple solutions to simple problems 🙂