SharePoint – How to Bulk Approve Folders using PowerShell

Admittedly this isn’t something you’d often need to do however I had a request to bulk approve folders and found very little information on how to do this in SharePoint using PowerShell so had to come up with my own way to do it.

Hopefully this helps –

The Code

Be sure to replace all the variables at the top as required.

This should be run on the SharePoint server.

Add-PSSnapin Microsoft.SharePoint.PowerShell

# Connect to sharepoint and site
$web = Get-SPWeb "*full link to site"
$list = $web.Lists["*name of library*"]
$time = Get-Date -Format g

# Get all folders in library which aren't approved
Write-Host -f white "Retrieving all folders not set to Approved Status in"$list.Title"library..."
$folders = $list.RootFolder.subFolders | where {$_.Item.ModerationInformation.Status -ne "Approved"} | select *

# Loop through the folders
foreach($folder in $folders) {
    Write-Host -f white "Attempting to update"$folder.Name

    # Update the status to approved and set a comment
    $folder.Item.ModerationInformation.Status = "Approved"
    $folder.Item.ModerationInformation.Comment = "Bulk Approved folder - " + $time

    # Try to update the folder in SP and notify user
    try {
        $folder.Item.Update()
        Write-Host -f green $folder.Name"in"$list.Title"library updated succesfully"
    } catch {
        Write-Host -f yellow "Failed to update"$folder.Name"folder in"$list.Title"library"
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s