Forum Discussion

Test SharePoint's avatar
Test SharePoint
Brass Contributor
Sep 12, 2018

get report of documents in SP site according to last accessed time/created by whom/last viewed time

Hello,

 

I want to get report of documents in a particular SP site (with their URLS) according to last accessed time/created by whom/last viewed time.

 

I tried running a custom report and got the most popular items list however it does not have complete data.

can someone please assist in this

 

thanks

  • This PowerShell script should do it.

     

    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) 
    {
    	Add-PSSnapin Microsoft.SharePoint.PowerShell;
    }
    
    function GetAllDocInventoryWithVersion([string]$siteUrl, $documentLibrary) {
    
    $SPWeb = Get-SPWeb $siteUrl #Change the SharePoint site name here#
    write-host SPWeb.Title
    $List = $SPWeb.Lists[$documentLibrary] #Change the document library name here#
    $ItemsColl = $List.Items
    $tableau =@();
    
    foreach ($item in $ItemsColl) 
    {
        $itemFileSize = $item.File.Length/1KB
        $o = new-object psobject
      
        $o | Add-Member -MemberType noteproperty -Name "ItemID" -value $item.ID;
        $o | Add-Member -MemberType noteproperty -Name "Item Title" -value $item.Title;
        $o | Add-Member -MemberType noteproperty -Name "Version" -value  "";#$item.Versions.Count;
        $o | Add-Member -MemberType noteproperty -Name "Item URL" -value $item.Url;    
        $o | Add-Member -MemberType noteproperty -Name "Comments" -value  $item.CheckInComment;
        $o | Add-Member -MemberType noteproperty -Name "File Size (KB)" -value $itemFileSize ;
        $o | Add-Member -MemberType noteproperty -Name "Created Date" -value $item["Created"]
        $o | Add-Member -MemberType noteproperty -Name "Created By" -value $item["Author"]
        $o | Add-Member -MemberType noteproperty -Name "Modifed Date" -value $item["Created"]
        $o | Add-Member -MemberType noteproperty -Name "Modifed By" -value $item["Editor"]
        $tableau += $o;
        
        foreach($Ver in $item.Versions)
         {
            $verFileSize = $item.File.Versions.GetVersionFromLabel($Ver.VersionLabel).Size/1KB
            $v = new-object psobject
            $comment = $item.File.Versions.GetVersionFromLabel($Ver.VersionLabel).CheckInComment
               
            $v | Add-Member -MemberType noteproperty -Name "ItemID" -value $item.ID;
            $v | Add-Member -MemberType noteproperty -Name "Item Title" -value $item.Title;
            $v | Add-Member -MemberType noteproperty -Name "Version" -value  $Ver.VersionLabel;
            $v | Add-Member -MemberType noteproperty -Name "Item URL" -value $Ver.Url;
            $v | Add-Member -MemberType noteproperty -Name "Comments" -value  $comment;    
            $v | Add-Member -MemberType noteproperty -Name "File Size (KB)" -value $verFileSize;
            $v | Add-Member -MemberType noteproperty -Name "Created Date" -value $Ver["Created"]
            $v | Add-Member -MemberType noteproperty -Name "Created By" -value $Ver["Author"]
            $v | Add-Member -MemberType noteproperty -Name "Modifed Date" -value $Ver["Created"]
            $v | Add-Member -MemberType noteproperty -Name "Modifed By" -value $Ver["Editor"]
            $tableau += $v;
           
         }
    }
    
    $SPWeb.Dispose();
    #$tableau| Out-GridView
    return $tableau
    }
    
    
    
    
    
    GetAllDocInventoryWithVersion "https://SharePoint2013" "Program Management"| Out-GridView
    • Test SharePoint's avatar
      Test SharePoint
      Brass Contributor

      Hey got the following errors:

       

      At line:2 char:20
      + $SPWeb = Get-SPWeb $http://abc.com/xyz #Change
      the ...
      + ~~~~~~
      Variable reference is not valid. ':' was not followed by a valid variable name
      character. Consider using ${} to delimit the name.
      At line:4 char:28
      + $List = $SPWeb.Lists[$Test's Excel Reporting] #Change the document library
      name ...
      +
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      The string is missing the terminator: '.
      At line:4 char:28
      + $List = $SPWeb.Lists[$Test's Excel Reporting] #Change the document library
      name ...
      + ~
      Missing ']' after array index expression.
      At line:4 char:28
      + $List = $SPWeb.Lists[$Test's Excel Reporting] #Change the document library
      name ...
      +
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Unexpected token ''s Excel Reporting] #Change the document library name here#
      $ItemsColl = $List.Items
      $tableau =@();' in expression or statement.
      At line:1 char:76
      + function GetAllDocInventoryWithVersion([string]$siteUrl, $documentLibrary) {
      + ~
      Missing closing '}' in statement block.
      + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
      ception
      + FullyQualifiedErrorId : InvalidVariableReferenceWithDrive

       

      You cannot call a method on a null-valued expression.
      At line:1 char:1
      + $SPWeb.Dispose();
      + ~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull


      At line:1 char:1
      + }
      + ~
      Unexpected token '}' in expression or statement.
      + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
      ception
      + FullyQualifiedErrorId : UnexpectedToken


      GetAllDocInventoryWithVersion : The term 'GetAllDocInventoryWithVersion' is
      not recognized as the name of a cmdlet, function, script file, or operable
      program. Check the spelling of the name, or if a path was included, verify
      that the path is correct and try again.
      At line:1 char:1
      + GetAllDocInventoryWithVersion "https://SharePoint2013" "Program Management"|
      Out ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (GetAllDocInventoryWithVersion:S
      tring) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

       

      • spucelik's avatar
        spucelik
        Icon for Microsoft rankMicrosoft

        I was able to paste the exact code below and run it successfully.  Make sure you're running this from the SharePoint server where it has access to the SharePoint dll's.

Resources