PoshCode Logo PowerShell Code Repository

SharePoint Large Lists (modification of post by view diff)
View followups from Peter | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1251"></script>download | new post

Provides details for every large list in the farm. As it is utilitarian, this script does not provide periodic status updates, though it could be programmed to do so.

Output is intended to be pasted into and analyzed in Excel.

  1. [reflection.assembly]::loadwithpartialname("Microsoft.SharePoint")
  2. $cs = [microsoft.sharepoint.administration.spwebservice]::ContentService
  3. $global:largeListThreshhold = 2000
  4.  
  5. function Is-Admin([Microsoft.SharePoint.SPRoleAssignment]$roleAssignment)
  6. {
  7.         return (($roleAssignment.roledefinitionbindings | where { ($_.BasePermissions.ToString() -match "ManageLists|ManageWeb|FullMask") }) -ne $null)
  8. }
  9.  
  10. function Write-ListDetails($list,$web,$site)
  11. {
  12.         $fields = @()
  13.         $fields += $list.Title
  14.         $fields += $list.RootFolder
  15.         $fields += ($list.ContentTypes | select -first 1).Name
  16.         $fields += ($list.ContentTypes | select -first 1).Id.ToString()
  17.         $fields += ($list.ContentTypes | select -first 1).Id.Parent.ToString()
  18.         $fields += $list.Items.NumberOfFields
  19.         $fields += $list.Items.Count
  20.         $fields += $list.Created
  21.         $fields += $list.LastItemModifiedDate
  22.        
  23.         $listAdmins = @()
  24.         $listAdmins += $list.RoleAssignments | where { Is-Admin $_ }
  25.        
  26.         if ($listAdmins.Count -gt 0)
  27.         {
  28.                 $fields += $listAdmins[0].Member.Name
  29.                 $fields += $listAdmins[0].Member.Email
  30.                 $fields += [string]::Join("; ", @($listAdmins | % { $_.Member.ToString() } ))
  31.         } else {
  32.                 $fields += ""
  33.                 $fields += ""
  34.                 $fields += ""
  35.         }
  36.         $fields += $web.Url
  37.         $fields += $web.Title
  38.         $fields += $site.Url
  39.        
  40.         [string]::Join("`t", $fields)
  41. }
  42.  
  43. function Enumerate-LargeListsInSite($siteCollection)
  44. {
  45.         foreach ($web in $siteCollection.AllWebs) {
  46.                 $web.Lists | where { $_.Items.Count -gt $global:largeListThreshhold } | foreach { Write-ListDetails -list $_ -web $web -site $siteCollection }
  47.                
  48.                 $web.Dispose()
  49.         }
  50. }
  51.  
  52. function List-FieldNames
  53. {
  54.         $fieldNames = @()
  55.         $fieldNames += "ListTitle"
  56.         $fieldNames += "ListRootFolderURL"
  57.         $fieldNames += "ContentType1Name"
  58.         $fieldNames += "ContentType1ID"
  59.         $fieldNames += "ContentType1ParentID"
  60.         $fieldNames += "NumberOfFields"
  61.         $fieldNames += "Items"
  62.         $fieldNames += "CreatedDate"
  63.         $fieldNames += "LastItemModifiedDate"
  64.         $fieldNames += "ListAdmin1Name"
  65.         $fieldNames += "ListAdmin1Email"
  66.         $fieldNames += "AllListAdmins"
  67.         $fieldNames += "WebURL"
  68.         $fieldNames += "WebTitle"
  69.         $fieldNames += "SiteURL"
  70.        
  71.         return [string]::Join("`t", $fieldNames)
  72. }
  73.  
  74. function Enumerate-LargeLists
  75. {
  76.         List-FieldNames
  77.                
  78.         $webApplications = $cs.WebApplications | foreach { $_ }
  79.         foreach ($webApplication in $webApplications) {
  80.                 $webApplication.Sites | foreach {
  81.                         Enumerate-LargeListsInSite -siteCollection $_
  82.                        
  83.                         $_.Dispose()
  84.                 }
  85.         }
  86. }
  87.  
  88.  
  89. #USAGE: paste contents into PowerShell window; call "Enumerate-LargeLists > yourtextfilename.txt"
  90. #then paste contents of text file into Excel spreadsheet. Output is
  91. #intended to be perused and analyzed in Excel.

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me