So I decided to use Powershell to iterate through a site collection of my choosing and output into a csv file. I could then do a quick calculation on all the documents to get a total size.
This script works fine, except at the end it will throw an error on the dispose function. If anyone can help resolve that, please feel free to leave a comment and I'll update my post. This script can also be adjusted to run against an entire we application as well.
Add this code to a text document and rename it with a .ps1 extension:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function Get-OldDocuments([string] $SiteURL)
{
$Site = Get-SPSite $SiteURL
foreach ($SPWeb in $SPSite.AllWebs)
{
foreach ($SPList in $SPWeb.Lists)
{
# Get Document Libraries
if ($SPList.BaseType -eq "DocumentLibrary")
{
foreach ($item in $SPList.Items)
{
$data = @{
"Site" = $SPSite.Url
"Web" = $SPWeb.Url
"list" = $SPList.Title
"Item URL" = $item.Url
"Item Title" = $item.Title
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"Size (KB)" = $item.File.Length/1KB
"Size (MB)" = $item.File.Length/1MB
}
# add files older than 1yr old
$expireDate = Get-Date
$expireDate = $expireDate.AddYears(-1)
if($item["Modified"] -lt $expireDate)
{
Write-Host($SPSite.Url +"/"+ $item.Url)
New-Object PSObject -Property $data
}
}
}
}
$SPWeb.Dispose();
}
$SPSite.Dispose()
}
#call the function
Get-OldDocuments "http://sharepoint.com/site" | Export-Csv -NoTypeInformation -Path C:\temp\OldDocuments.csv
This script works fine, except at the end it will throw an error on the dispose function. If anyone can help resolve that, please feel free to leave a comment and I'll update my post. This script can also be adjusted to run against an entire we application as well.
Add this code to a text document and rename it with a .ps1 extension:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function Get-OldDocuments([string] $SiteURL)
{
$Site = Get-SPSite $SiteURL
foreach ($SPWeb in $SPSite.AllWebs)
{
foreach ($SPList in $SPWeb.Lists)
{
# Get Document Libraries
if ($SPList.BaseType -eq "DocumentLibrary")
{
foreach ($item in $SPList.Items)
{
$data = @{
"Site" = $SPSite.Url
"Web" = $SPWeb.Url
"list" = $SPList.Title
"Item URL" = $item.Url
"Item Title" = $item.Title
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"Size (KB)" = $item.File.Length/1KB
"Size (MB)" = $item.File.Length/1MB
}
# add files older than 1yr old
$expireDate = Get-Date
$expireDate = $expireDate.AddYears(-1)
if($item["Modified"] -lt $expireDate)
{
Write-Host($SPSite.Url +"/"+ $item.Url)
New-Object PSObject -Property $data
}
}
}
}
$SPWeb.Dispose();
}
$SPSite.Dispose()
}
#call the function
Get-OldDocuments "http://sharepoint.com/site" | Export-Csv -NoTypeInformation -Path C:\temp\OldDocuments.csv
No comments:
Post a Comment