Home > Blogs > Eric Shupps | The SharePoint Cowboy > Posts > Using PowerShell to Approve List Items
 
​The SharePoint Cowboy


photo of Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA
December 13
Using PowerShell to Approve List Items

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 :-)

 

Comments

thanks

great work - thanks for the tip!
 on 3/9/2011 6:39 PM

Re: Using PowerShell to Approve List Items

This is awesome.  Thank you very much.  My only question is how would you do this so that both files and folders get approved?  I ran the script above (modified for my environment) and all files got approved but the folders did not.
 on 3/16/2011 1:10 PM

Nice!

Interesting post and thanks for sharing. Some things in here I have not thought about before, This blog has given me opportunity to learn many things regarding products and services.
http://www.fprinting.com/custom-vinyl-decals-for-cars/
 on 7/13/2011 11:30 AM

Thanks

Thanks Buddy for sharing the information. Saved me a lot of headache.
 on 1/16/2013 6:38 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Comment Date *

Select a date from the calendar.
Enter the current date to prevent automated spambot comments.

Spam Prevention *


How many letters, not including spaces, does it take to spell "SharePoint Cowboy"?

Attachments

 

 




Copyright © 2013 BinaryWave, Inc. All rights reserved.