Identifying all checked-out publishing pages in a site with PowerShell

Using the publishing features, SharePoint provides a great methodology for content editors to use when collaborating on items. In many cases, there is one flaw in this methodology, the users. It is very common for users to check out content and then forget to check in again. In this recipe, we will use PowerShell to identify all the publishing pages in a site that are currently checked out.

Tip

Users with the permissions to manage the list or library, such as site administrators, have the ability to override a check out. This can be useful if the user who checked out the item is not available to check in the item.

How to do it...

Follow these steps to identify checked-out publishing pages using PowerShell:

  1. Open your preferred text editor to create the ps1 script file.
  2. Get the site using the Get-SPWeb Cmdlet as follows:
    $web = Get-SPWeb "http://sharepoint/publishing"
    
  3. Get the publishing site from the SharePoint site.
    $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    
  4. Get the publishing pages from the publishing site.
    $pages = $pubWeb.GetPublishingPages()
    
  5. Iterate through each page in the collection of publishing pages using the following command:
    foreach ($page in $pages)
    
  6. Check the Level property of the publishing page file to see if the item is checked out.
    if ($page.ListItem.File.Level -eq [Microsoft.SharePoint.SPFileLevel]::Checkout)
    
  7. If the publishing page is checked out, output the details.
    Write-Host $page.Url
    
    Write-Host "By: " $page.ListItem.File.CheckedOutByUser.LoginName
    
    Write-Host "Since: " $page.ListItem.File.CheckedOutDate.ToString()
    
    Write-Host ""
    
  8. Use the Dispose method to discard the SPWeb object as follows:
    $web.Dispose()
    
  9. Save the file as a ps1 file, for example, getcheckedoutpages.ps1
  10. Execute the script in the PowerShell session using the following command:
    ./getcheckedoutpages.ps1
    

How it works...

Obtaining the SharePoint list item object associated with a publishing page provides the details necessary to identify whether a page is checked out and who has checked it out.

There's more...

Identifying checked out publishing pages may also be accomplished with code using the server-side object model. Follow these steps to identify checked-out publishing pages with code using the server-side object model:

  1. Open the site collection containing the site in a using statement as follows:
    using (var site = new SPSite("http://sharepoint/publishing"))
  2. Open the site in a using statement as follows:
    using (var web = site.OpenWeb())
  3. Get the publishing site from the SharePoint site.
    var pubWeb = PublishingWeb.GetPublishingWeb(web);
  4. Get the publishing pages from the publishing site.
    var pages = pubWeb.GetPublishingPages();
  5. Iterate through each page in the collection of publishing pages using the following line of code:
    foreach (var page in pages)
  6. Check the Level property of the publishing page to see if the item is checked out.
    if (page.ListItem.File.Level == SPFileLevel.Checkout)
  7. If the publishing page is checked out, output the details.
    Console.WriteLine(page.Url);
    
    Console.WriteLine("By: " + page.ListItem.File.CheckedOutByUser.LoginName);
    
    Console.WriteLine("Since: " + page.ListItem.File.CheckedOutDate.ToString());
    
    Console.WriteLine("");
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.61.218