Sep 12 2018 09:50 AM
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
Sep 12 2018 10:13 AM
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
Sep 12 2018 10:15 AM
Awesome. will try this out. thanks!!
Sep 12 2018 11:29 AM
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
Sep 12 2018 12:50 PM
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.
Sep 12 2018 12:59 PM
thanks for your response. i got the most of the errors removed. i am running this on Sp server however the only error remaining no is for the last command:
GetAllDocInventoryWithVersion "https://SharePoint2013" "Program Management"| Out-GridView
The error:
Get-SPWeb : Cannot find an SPSite object that contains the following Id or Url:
https://SharePoint2013=http://abc.com/xyz.
At line:8 char:10
+ $SPWeb = Get-SPWeb $siteUrl="http://abc.com/xyz"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletPi
peBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb
SPWeb.Title
Cannot index into a null array.
At line:10 char:9
+ $List = $SPWeb.lists[$documentLibrary] = "SSRS Reporting"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
You cannot call a method on a null-valued expression.
At line:53 char:1
+ $SPWeb.Dispose();
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I also tried the following command:
Get-AllDocInventoryWithVersion "http://abc.com/xyz" | Export-Csv -NoTypeInformation -Path "C:\Users\Desktop\sitecollectionreport.csv"
the error:
Get-AllDocInventoryWithVersion : The term 'Get-AllDocInventoryWithVersion' 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:57 char:1
+ Get-AllDocInventoryWithVersion "http://abc.com/xyz ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AllDocInventoryWithVersion:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Sep 12 2018 01:05 PM
the GetAllDocInventoryWithVersion statement is simply calling the function with the specified parameters. Replace "https://SharePoint2013" with your site that contains the document library. Also replace "Program Management" with the name of the document library. It should work then.
Sep 12 2018 01:14 PM
Apologies, I had changed it. this is the error i am receiving after inserting the URL and document library URL:
Sep 12 2018 01:18 PM
Typically this means that the URL it not to a site. Make sure it's going to the site level and not any deeper. For example:
Site = http://sharepoint/sites/hr is the root of the HR site
Within that site will be the name of the library. Use the name that is in Library Setttngs and not the URL.
Sep 12 2018 01:25 PM
Sep 13 2018 09:39 AM
I am running windows powershell ISE as an administrator and get the following error:
Get-SPWeb : Cannot find an SPSite object that contains the following Id or Url:
https://abc.com=https://abc.com.
At line:8 char:10
+ $SPWeb = Get-SPWeb $siteUrl="https://abc.com"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletPi
peBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb
SPWeb.Title
Cannot index into a null array.
At line:10 char:9
+ $List = $SPWeb.lists[$documentLibrary] = "Auditing"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
You cannot call a method on a null-valued expression.
At line:53 char:1
+ $SPWeb.Dispose();
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull