Wednesday, 18 December 2013

Top Document Authors

I work in municipal government in Canada, we are having legislation come through that requires new documents (pdf's, docx, etc) to be accessible. To begin our training of content creators we required a way to identify our number one document contributors, this is the script to accomplish this:

<#
.Synopsis
   List Users by number of Documnets
.DESCRIPTION
   This script lists all docuemnt authors by the number of docs they've created
.EXAMPLE
  Get-SPMAuthors -SiteUrl http://ssrap1 -OutputPath c:\output.csv
#>
function Get-SPMAuthors
{
    [CmdletBinding()]
    [OutputType([int])]
    Param
    (
        # the site app url ie http://wingtipserver
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$False,
                   Position=0)]
              [string]
        $SiteUrl,
              # pass in the output path for the csv
              [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$False,
                   Position=1)]
              [string]
              $OutputPath         
    )

    Begin
    {
              $SiteApp = Get-SPSite $SiteUrl
              $table = New-Object system.Data.DataTable "Documents"
              $col1 = New-Object system.Data.DataColumn CreatedBy,([string])
              $table.columns.add($col1)
    }
    Process
    {
              $SiteApp.AllWebs | % {
                     $docLib = $_.Lists["Documents"]
                     $docLib.Items | % {
                           $row = $table.NewRow()
                           $row.CreatedBy = $_["Created By"]
             
                           $table.Rows.Add($row)
                     }     
              }
             
              $groupedTable = $table | Group-Object CreatedBy | sort Count –Descending
              $groupedTable | select Count, Name | export-csv $OutputPath -noType
    }
    End
    {
              $col1.Dispose()
              $table.Dispose()
              $SiteApp.Dispose()
    }

}