PowerShell to get SharePoint 2010 field name from site collection

param
(
 [Parameter(Mandatory=$true, HelpMessage=’-Url http://sharepointurl/site/test – Please provide the Url of the Site.’)]
 [string]$Url=””,
 [Parameter(Mandatory=$true, HelpMessage=’-FieldName – Please provide the Internal Field Name to remove.’)]
 [string]$FieldName=””,
 [Parameter(Mandatory=$true, HelpMessage=’-FieldType – Please provide the Field Type to remove.’)]
 [string]$FieldType=””
 
);

$site = Get-SPSite -Identity $Url -ErrorAction SilentlyContinue;
if($site -ne $null)
{
 Write-Host “Checking Site Collection:” $Url “Field:” $FieldName “….”-NoNewline;
 $checkSiteColumn = $site.RootWeb.Fields | ?{($_.InternalName -eq $FieldName) -and ($_.TypeAsString -eq $FieldType)};
 if($checkSiteColumn -eq $null)
 {
  Write-Host “Field Not Found!” -ForegroundColor Yellow;
 }
 else
 {
  Write-Host “Field Found” -ForegroundColor Green;
 }
 
 foreach($checkWeb in $site.AllWebs)
 {
  $caseFileList = $checkWeb.Lists.TryGetList(“Case Files”);
  if($caseFileList -ne $null)
  {
   Write-Host “Checking CaseFiles DocLib in” $checkWeb.ServerRelativeUrl “…”-NoNewline;
   $checkField = $caseFileList.Fields | ?{($_.InternalName -eq $FieldName) -and ($_.TypeAsString -eq $FieldType)};
   if($checkField -eq $null)
   {
    Write-Host “Not Found!” -ForegroundColor Yellow;
   }
   else
   {
    Write-Host “Found!” -ForegroundColor Green;
   }
  }
 }
 
}
else
{
 Write-Host “Site: ” $Url ” Not Found” -ForegroundColor Yellow;

Advertisements

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 )

Google+ photo

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

Connecting to %s