Friday, 23 May 2014

Get all checked out pages from entire site collection

Usually when we migrate content from one server to other, all the pages and documents should be cheked-in, otherwise the pages might be locked by the system account for editing or some times the pages might get corrupted.

I have written this script, so that we can get all the checked out pages and make sure they are checked in before we take a content database backup.

.ps1 code

# Add SharePoint cmdlets reference
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

function enumerateWebParts($Url) {
    $site = new-object Microsoft.SharePoint.SPSite $Url

    foreach($web in $site.AllWebs) {
        $pages = $web.Lists["Pages"]
        #Write-Host "Processing Web:" $pWeb.Url "..." -ForegroundColor Magenta
    $pCheckedOut = $pages.CheckedOutFiles
    foreach($p in $pCheckedOut){
        $p | select-object @{Expression={$web.Url};Label="Web URL"},@{Expression={$_.Url};Label="Page URL"}, @{Expression={$_.CheckedOutBy};Label="Checked Out By"}, @{Expression={$_.CheckedOutBy.Email};Label="Checked Out Email"}, @{Expression={"No"};Label="Checked In Version"}

    }
foreach ($item in $pages.Items) {
                if ($item.File.CheckOutStatus -ne "None") {
$item| select-object @{Expression={$Web.Url};Label="Web URL"},@{Expression={$_.File.Url};Label="Page URL"}, @{Expression={$_.File.CheckedOutBy};Label="Checked Out By"}, @{Expression={$_.File.CheckedOutBy.Email};Label="Checked Out Email"}, @{Expression={"Yes"};Label="Checked In Version"}
}
}
   
    $web.Dispose()
    }
 }
$webAppUrl = Read-Host "Enter the web application URL for ex:test.com"
$csvpath = Read-Host "Enter the csv file path to create for ex: c:\test.csv"

$row = enumerateWebParts($webAppUrl)
$row | Export-Csv $csvpath

No comments:

Post a Comment