Friday 23 March 2012

List Existing site Columns using Powershell

Powershell script

[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

function GetSiteColumns($web)
{
    foreach ($f in $web.Fields)
    {
        $data = @{"Id" = $f.Id
                  "Title" = $f.Title
                  "Type" = $f.Type
                  "Internal Name" =  $f.InternalName
                   "Group" = $f.Group
                  }
                  New-Object PSObject -Property $data   
    }
}

$webUrl = "http://ssrap2"
GetSiteColumns(Get-SPWeb $webUrl) | Out-GridView

remember to swap out the url highlighted in yellow to your own, for this to work you need to have windows powershell ISE installed.

I've been uping my PowerShell skills as of late,
and here's a much more impressive way to achieve the same result


#function to load SharePoint Powershell snap in
function LoadSharePointPowerShellEnviroment
{
 #clear the screen of pevious output
 Clear-Host
 write-host "Setting up Powershell enviroment for Sharepoint" -foregroundcolor Blue
 Add-PSSnapin "Microsoft.Sharepoint.PowerShell" -ErrorAction SilentlyContinue
 Write-host "Sharepoint PowerShell Snapin loaded." -foregroundcolor Green
}
#call sharepoint plugin function
LoadSharePointPowerShellEnviroment
$web = Get-SPWeb("http://Wingtip")
$web.Fields | Select-Object -Property id, Title, type,InternalName, Group  | Out-GridView
$web.dispose()