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
          $result | Out-File OldDocuments.csv -Append
        }
      }
    }
  }
}

 

 

Versioning is a great SharePoint feature that allows for life's little mistakes to be forgiven.  However, if not configured with care, versioned documents can quickly consume significant amounts of space in your content databases.  If you have many people that can configure document library properties, this can become a major issue as each person may have their own idea about appropriate versioning settings.

The following script will perform the following actions against a SharePoint farm:

I wrote this script to help combat a single ballooning site collection content database.  After running the script, said content database was reduced by 20 GB. Enjoy!

# Title: Set-SPVersioningLimit
# Version: 1.0 29FEB12
# Author: James Sanders
# Purpose: Enumerate all portal lists to determine which have versioning enabled. For lists that have versioning enabled, set Major Version Limit to 3 and clean up items

# Load SharePoint PowerShell extensions
"- Loading SharePoint extensions"
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
"- Enumerating web sites"
$webs = Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All
"- Enumerating versioned lists"
ForEach ($web in $webs) {
  ForEach ($list in $web.Lists) {
    If ($list.EnableVersioning -eq $TRUE) {
      "`nChecking list: $($web.Url)/$list"
      If ($list.MajorVersionLimit -ne 3) {
        $list.MajorVersionLimit = 3
        $list.Update()
        ForEach ($item in $list.Items) {
          "Versioning $($item.URL)"
          $item.SystemUpdate()
        }
      }
      Else { "Major version limit already configured correctly" }
    }
  }
}

When you attempt to "Save list as template", the "Include Content" check box is disabled.  This can happen for one of two reasons:

A custom list template can be developed with the DontSaveInTemplate attribute configured and the value set to True.  The standard SharePoint Issues list is configured this way also.  To check a list and see if the ExcludeFromTemplate property is true:

$web = Get-SPWeb http://site_with_list
$list = $web.lists | Where-Object {$_.Title -eq "List Title"}
$list.ExcludeFromTemplate

The ExcludeFromTemplate property is read-only and cannot be changed.  Fortunately, you can use Central Administration to perform a granular backup of the list, and then use the PowerShell Import-SPWeb cmdlet to import the list with contents to the desired location.  Yay!

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