SharePoint PowerShell Locate Libraries with specific Columns

Here’s a little PowerShell Script I wrote to list all Document Libraries that contain a specific Column. I have specifically checked to see if the BaseTemplate is a library, however you can remove that part of the script and look for all Lists or a specific List type e.g. announcements or calendar.

It can be easily modified to display other details using these documents as a reference:

SharePoint List Properties: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list_properties.aspx

SharePoint Field Properties: http://msdn.microsoft.com/en-us/library/aa544201.aspx

$fieldname="ColumnName"
 $s = Get-SPSite http://sharepoint
 $wc = $s.AllWebs
 foreach($w in $wc){
   foreach($l in $w.Lists){
    if($l.BaseTemplate -eq "DocumentLibrary"){
      for ($i = 0; $i -lt $l.fields.Count; $i++)
      {
        if($l.fields[$i].Title -eq $fieldname){
          write-host $l.ParentWebURL,",",$l.Title,",", $l.fields[$i].Title,",",$l.ID
        }
      }
   }
  }
 }

Another useful script is this one to export a list of Site Columns and Associated Lists:

$fieldname="ColumnName"
$web = Get-SPWeb http://sharepoint
$column = $web.Fields[$fieldname]
$column.ListsFieldUsedIn()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s