sharepoint inventory of files

pma111
pma111 used Ask the Experts™
on
does anyone know of any scripts which can document all files in a sharepoint environment, with the basics like filename, path, file added/created, file last edited, file last accessed. This is for sharepoint 2013?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software/web developer
Commented:
Here is your Powershell script.

foreach($app in (get-spwebapplication)) {
	foreach($site in $app.Sites) {
		foreach($web in $site.AllWebs) {
			Write-Host -F Cyan $web.Url
			foreach($list in $web.Lists) {
				if ($list -is [Microsoft.SharePoint.SPDocumentLibrary]) {
					Write-Host -F DarkCyan $list.Title, $list.ItemCount
					$query = New-Object Microsoft.SharePoint.SPQuery
					$query.ViewAttributes = "Scope='RecursiveAll'"
					$query.Query = "<Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='Text'>0x0101</Value></BeginsWith></Where>"
					$query.ViewFields = "<FieldRef Name='FileRef'/><FieldRef Name='Created'/><FieldRef Name='Modified'/>"
					$query.ViewFieldsOnly = $true
					foreach($item in $list.GetItems($query)) {
						$item | Select-Object -Property @{E={[Microsoft.sharePoint.Utilities.SPUrlUtility]::CombineUrl($web.URl, $item.File.Url)};L='Url'},@{E={$_['Created']};L='Created'},@{E={$_['Modified']};L='Modified'} |`
							Export-Csv -Append -Path 'c:\temp\results.csv' -Encoding UTF8 -NoTypeInformation
					}
				}
			}
			$web.Dispose()
		}
		$site.Dispose()
	}
}

Open in new window


There is no way to get 'last access time' information. SharePoint does not provide this information. You must setup site collection audit or use other monitoring software (say get this info from IIS logs).

Author

Commented:
is there a pre-requisite for get-spwebapplication - I ran it on a sharepoint app server using powershell ISE, and it did not recognise that command at all.
Piotr StrycharzSoftware/web developer

Commented:
This should run on all SharePoint servers. Are you sure you run this script in SharePoint 2013 PowerShell console?
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Author

Commented:
or should it be run within sharepoint management shell?

Author

Commented:
ah - from within the sharepoint 2013 management shell it does recognise get-spwebapplication - I was trying to run it using standard powershell ISE

Author

Commented:
Something is still a miss, we know there are approx. 7000 documents but it only returns approx. 70 rows. Is there a way to specify a specific web application and see if that produces a fuller report?
Piotr StrycharzSoftware/web developer

Commented:
The script lists all web applications. If you want to specify an application - remove outer loop (first, and last line in the script) and in the first line say:

$app=Get-SPWebApplication http://my-application

Open in new window


You may not have access to all the documents. Check the script output - it says what list is being processed and how many items it has. Compare to results you get.

Author

Commented:
Ah yeah, lots of access denied type errors :(
Piotr StrycharzSoftware/web developer

Commented:
You must use site collection admin account for all the sites. One of the solutions is to use application pool account, or even Central Admin pool account.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial