CheckIn and Approve all pages(PowerShell) SharePoint

Hello Folks,

After long time i am writing this blog.  here we gonna talk about checkin and publish all pages at once.

there are lots of ways to check in and approve pages at once. like from Site structure and powershell or you can check in and approve pages one by one from page library. but if you have 100s of  subsites in site collection so those method can be headache and painful for you.  so this script can help you out to checkin and approve all pages from your site collection even you have thousands of subsites in site collection.

 

function PublishAllPages ($url)

{

    $site = Get-SPSite -Identity $url

    #Walk through each Publishing Web and check in every page

    $site | Get-SPWeb -limit all | ForEach-Object {

        #Check to see if site is a publishing site

        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($_)) {

            write-host "Reviewing pages in"$_.Title"site...."

            #Get the Publishing Web and pages within it

            $publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)

            $publishingPages = $publishingWeb.GetPublishingPages()

            foreach ($publishingPage in $publishingPages)

            {

                #Check to ensure the page is checked out, and if so, check it in

                if ($publishingPage.ListItem.File.CheckOutStatus -ne "None")

                {

                    CheckInPage -page $publishingPage -web $_

                }

                else

                {

                    #Notify administrator that the page is already checked in

                    write-host $publishingPage.Title"("$publishingPage.Name") has already been checked in"

                }

                #Check to ensure page is checked in, and is so, approve it

                if ($publishingPage.ListItem.File.CheckOutStatus -eq "None")

                {

                    ApprovePage -page $publishingPage

                }

            }

        }

        else

        {

            #Notify administrator that the site is not a publishing site

            write-host $_.Title"is not a publishing site"

        }

    }

    #Dispose of the site object

    $site.Dispose()

}

function CheckInPage ($page, $web)

{

    #Check to ensure the page is checked out by you, and if so, check it in

    if ($page.ListItem.File.CheckedOutBy.UserLogin -eq $web.CurrentUser.UserLogin)

    {

        $page.CheckIn("Page checked in automatically by PowerShell script")

        write-host $page.Title"("$page.Name") has been checked in"

    }

    else

    {

        write-host $page.Title"("$page.Name") has not been checked in as it is currently checked out to"$page.ListItem.File.CheckedOutBy

    }

}

function ApprovePage ($page)

{

    if($page.ListItem.ListItems.List.EnableModeration)

    {

        #Check to ensure page requires approval, and if so, approve it

        if ($page.ListItem["Approval Status"] -eq 0)

        {

            write-host $page.Title"("$page.Name") is already approved"

        }

        else

        {

            $page.ListItem.File.Approve("Page approved automatically by PowerShell script")

            write-host $page.Title"("$page.Name") has been approved"

        }

    }

    else

    {

        write-host $page.Title"("$page.Name") does not require approval in this site"

    }

}

after running above script run the below command to call above script.

PublishAllPages -url sitecollectionurl

Thanks to  for this script!

Hope this help.

Happy SharePointing 😉

Advertisements

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