Locating Old Documents

By James|April 27, 2012|

This small script will crawl your farm and spit out a .CSV file with of all items that are more than a year old. It was quickly written due to an "i wonder ..." request.

# Title: Get-SPOldDocuments
# Version: 1.0 01MAR12
# Author: James Sanders
# Purpose: Find and display all documents that are at least one year old

# Load SharePoint PowerShell extensions
"- Loading SharePoint extensions"
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Set date query
$dateQuery = (Get-Date).AddYears(-1)
"Item, TimeStamp, Length" | out-file OldDocuments.csv

# Crawl web applications
"- Enumerating web sites"
$webs = Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All
"- Enumerating lists"
ForEach ($web in $webs) {
  ForEach ($list in $web.Lists) {
    If ($list.BaseType -eq "DocumentLibrary") {
      "`n- Checking Document Library: $($web.Url)/$list"
      ForEach ($item in $list.Items) {
        If ($item.URL.StartsWith("_")) {Break}
        If ($item.URL.EndsWith(".aspx")) {Break}
        If ($item.File.TimeLastModified -le $dateQuery) {
          $result = """$($web.URL)/$($item.URL)"", $($item.File.TimeLastModified), $($item.File.Length)"
          $result | Out-File OldDocuments.csv -Append



Copyright 2011 - 2021 The Lazy SharePoint Admin | All Rights Reserved
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram