Forum Discussion
get report of documents in SP site according to last accessed time/created by whom/last viewed time
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 SharePointSep 12, 2018Brass 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 : InvalidVariableReferenceWithDriveYou 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- spucelikSep 12, 2018
Microsoft
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.
- Test SharePointSep 12, 2018Brass Contributor
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-GridViewThe 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 : InvokeMethodOnNullI 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
- Test SharePointSep 12, 2018Brass Contributor
Awesome. will try this out. thanks!!