0

Today I had to get a count of items in a particular library. This library resides in all SPWebs in one of our site collections. In case anyone needs something like this I was able to achieve this by using the powershell script below.

$webapp = get-spwebapplication http://somewebapp.com;
foreach ($site in $webapp.sites)
{
        foreach ($web in $site.AllWebs)
        {
               $list = ($web.Lists | where-object {$_.title -eq “SomeName”})
               
               if($list.itemcount -gt 0)
               {    

$itemCount = $list.itemcount;
                       “SomeName Library located here: ” + $web.Url + ” has ” + $itemCount + ” items.” | Out-File -filepath C:\subtest1.txt -append
 
              }
               $web.dispose();
        }
        $site.dispose();
}

 

(Visited 29 times, 1 visits today)
Add a Comment