Pages

24 October 2011

Get all the Columns created

ISSUE DESCRIPTION:
Get a list of all created columns in a Site Collection.

Why would you want this ? 
Well in my case I got a BambooLookup Site Collection feature enable on a SharePoint 2007 Site, and I did not know where to find the created column using this feature.
My goal was to remove those column for a clean Migration to SharePoint 2010.


SOLUTION:
The solution is obviously to create a Powershell script.
param (
    [string]$Url = $(throw "Missing Site Collection Url (please use -url [URL])")
)

#Add Powershell CmdLet & Assembly
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Declare Log File
Function StartTracing
{
    $LogTime = Get-Date -Format yyyy-MM-dd_h-mm
    $script:LogFile = "ListAllColumnOutput-$LogTime.csv"
    Start-Transcript -Path $LogFile -Force
}

$site = new-object Microsoft.SharePoint.SPSite($url)

StartTracing

write-host "Web;List;ColTitle;ColId;ColType;ColType2" -foregroundcolor cyan

Foreach($web in $site.AllWebs)
{
    foreach ($list in $web.Lists)
    {
        foreach ($field in $list.Fields)
        {
        $Stringtype = $field.typeasstring
        $Name = $field.gettype().Name
        write-host $web.url -nonewline -foregroundcolor green
        write-host ";" -nonewline
        write-host $list.title -nonewline -foregroundcolor green
        write-host ";" -nonewline
        write-host $field.title -nonewline -foregroundcolor green
        write-host ";" -nonewline
        write-host $field.id  -nonewline -foregroundcolor green
        write-host ";" -nonewline
        write-host $Stringtype  -nonewline -foregroundcolor green
        write-host ";" -nonewline
        write-host $Name -foregroundcolor green
        }
    }
    $web.Dispose();
}
Stop-Transcript

Paste the above code in a PowerShellScript file, like [ListAllSiteColumns.ps1] and copy it on your local SharePoint Server Drive.

Launch the script from a Windows Powershell Cmd Prompt using the following parametters:
.\ListAllSiteColumns.ps1 -url <sitecollectionUrl>

After execution, the script generates a CSV output file in the same folder with details about the Columns (WebUrl/ListName/ColumnTitle/ColumnId/ColumnType/..).

Import the CSV file to excel and then you can filter / Sort the information easily to find what you are looking for.

0 comments:

Post a Comment