Let's say you want to know total number of document's in your SharePoint app including sub-site. Output is an excel file. Change the column in the script if you need additional columns here.
function Get-DocInventory($siteUrl, $outFileNameWithPath) {
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
foreach ($site in $spWebApp.Sites) {
foreach ($web in $site.AllWebs) {
foreach ($list in $web.Lists) {
if ($list.BaseType -ne "DocumentLibrary") {
continue}
if ($list.Hidden) {
continue}
foreach ($item in $list.Items) {
$data = @{
"Web Address" = $web.Url
"Doc Lib Name" = $list.Title
"File URL" = $item.Url
"File name" = $item.File.name
"Title" = $item.Title
"Created" = $item["Created"]
"Created By" = $item["Created By"]}
New-Object PSObject -Property $data}}
$web.Dispose();}
$site.Dispose()}
Write-Host "File written to " $outFileNameWithPath}
function Get-Docs()
{
$siteUrl = Read-Host "Enter Site URL"
$outFilePath = Read-Host "Enter output file path (without file name)"
$outFileNameWithPath = $outFilePath.ToString() + "\uploadedDocs.csv"
Get-DocInventory $siteUrl $outFileNameWithPath
Export-Csv -NoTypeInformation -Path $outFileNameWithPath
}
#Set-ExecutionPolicy RemoteSigned
Get-Docs
function Get-DocInventory($siteUrl, $outFileNameWithPath) {
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
foreach ($site in $spWebApp.Sites) {
foreach ($web in $site.AllWebs) {
foreach ($list in $web.Lists) {
if ($list.BaseType -ne "DocumentLibrary") {
continue}
if ($list.Hidden) {
continue}
foreach ($item in $list.Items) {
$data = @{
"Web Address" = $web.Url
"Doc Lib Name" = $list.Title
"File URL" = $item.Url
"File name" = $item.File.name
"Title" = $item.Title
"Created" = $item["Created"]
"Created By" = $item["Created By"]}
New-Object PSObject -Property $data}}
$web.Dispose();}
$site.Dispose()}
Write-Host "File written to " $outFileNameWithPath}
function Get-Docs()
{
$siteUrl = Read-Host "Enter Site URL"
$outFilePath = Read-Host "Enter output file path (without file name)"
$outFileNameWithPath = $outFilePath.ToString() + "\uploadedDocs.csv"
Get-DocInventory $siteUrl $outFileNameWithPath
Export-Csv -NoTypeInformation -Path $outFileNameWithPath
}
#Set-ExecutionPolicy RemoteSigned
Get-Docs