Thursday, September 19, 2013

Identifying Problem Publishing Image Libraries

The problem:

In one of my previous posts (http://kiwiboris.blogspot.com/2013/08/migrating-publishing-images-libraries.html) I talked about publishing images libraries and how the images from these libraries might need to be re-migrated and the specific steps needed to create such libraries and perform the migration. It is nice, however, to identify all such problem libraries in every site collection on the farm. Usually, when these libraries are not migrated correctly, one of the symptoms is that each image is checked out by the farm admin (the reason is that since the metadata for these images is faulty they cannot be checked in.)

The solution:

First of all, it is useful to remember that the base template for the publishing images library is 851 (fa propos, it is 850 for the publishing pages library.) Also, we are only interested in the libraries that have at least one item, each of them checked out. The following script will do the job:

cls

$w = Get-SPSite "https://main.coolsite.myserver.com"
$wa = $w.WebApplication

$wa.Sites | % {
   $_.AllWebs | % {
    $_.Lists | Where-Object { $_.BaseTemplate -eq 851 -and $_.Items.Count -gt 0} | % {
       $itemsCheckedOutCount = $_.Items | Where-Object { $_.File.CheckOutType -ne "None" } | Measure-Object
       if ($itemsCheckedOutCount.Count -eq $_.Items.Count)
       {
            Write-Host "All the images in the document library" $_.Title "in site" $_.ParentWeb.URL "are checked out"
       }
    }
   }
}

$w.Dispose()