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.
Follow these steps to identify checked-out publishing pages using PowerShell:
ps1
script file.Get-SPWeb
Cmdlet as follows:$web = Get-SPWeb "http://sharepoint/publishing"
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pubWeb.GetPublishingPages()
foreach ($page in $pages)
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)
Write-Host $page.Url Write-Host "By: " $page.ListItem.File.CheckedOutByUser.LoginName Write-Host "Since: " $page.ListItem.File.CheckedOutDate.ToString() Write-Host ""
Dispose
method to discard the SPWeb
object as follows:$web.Dispose()
ps1
file, for example, getcheckedoutpages.ps1
./getcheckedoutpages.ps1
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.
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:
using
statement as follows:using (var site = new SPSite("http://sharepoint/publishing"))
using
statement as follows:using (var web = site.OpenWeb())
var pubWeb = PublishingWeb.GetPublishingWeb(web);
var pages = pubWeb.GetPublishingPages();
foreach (var page in pages)
Level
property of the publishing page to see if the item is checked out.if (page.ListItem.File.Level == SPFileLevel.Checkout)
Console.WriteLine(page.Url); Console.WriteLine("By: " + page.ListItem.File.CheckedOutByUser.LoginName); Console.WriteLine("Since: " + page.ListItem.File.CheckedOutDate.ToString()); Console.WriteLine("");
3.22.61.218