magritton
8/4/2016 - 1:21 PM

Powershell find occurrences of a specific field type in SharePoint

Powershell find occurrences of a specific field type in SharePoint

$webApp = Get-SPWebApplication https://xxxxx
$fieldType = 'CascadingDropDownFieldType' #[Guid]"{becafe54-ff71-416b-bc43-959aab6b07f7}"

foreach($site in $webApp.Sites){
	
	#if($site.Url -eq 'https://homeportnwtest.psns.navy.mil/cmdtools/tools'){
		Write-Host "Site URL: " + $site.Url -background yellow -foreground black
		<# foreach($web in $site.AllWebs)  
		{           
		  foreach($list in $web.Lists)  
		  {
			$fieldInUseList = $list.Fields | Where {$_.TypeAsString -eq $fieldType}
			$fieldInUseCt = $fieldInUseList.Count
			if($fieldInUseCt -gt 0) {
				foreach($field in $fieldInUseList){
					Write-Host "'$web' web - Found a match in the '$field' field in the '$list' list"
					"'$web' web - Found a match in the '$field' field in the '$list' list" | out-file 'E:\Logfiles\Cascade.txt' -append
					$list.Url | out-file 'E:\Logfiles\Cascade.txt' -append
				}
			}            
		  }
		  foreach($ct in $web.ContentTypes) {
			 $fieldInUseCt = $ct.FieldLinks | Where {$_.TypeAsString -eq $fieldType }
			 $fieldInUseCt = $fieldInUseList.Count
			if($fieldInUseCt -gt 0) {
				foreach($field in $fieldInUseList){
					Write-Host "'$web' web - Found a match in the '$field' field in the '$ct' Contenttype"
					"'$web' web - Found a match in the '$field' field in the '$ct' Contenttype" | out-file 'E:\Logfiles\Cascade.txt' -append
					$list.Url | out-file 'E:\Logfiles\Cascade.txt' -append
				}
			 }
		  }
		} #>
	#}
}
$fieldId = [Guid]"fa564e0f-0c70-4ab9-b863-0177e6ddd247"

$site = Get-SPSite("http://yoursite/") 

foreach($web in $site.AllWebs)  
{            
  foreach($list in $web.Lists)  
  {
    $fieldInUseList = $list.Fields | Where {$_.Id -eq $fieldId }
    if($fieldInUseCt) {
        Write-Host "'$web' web - Found a match in the '$field' field in the '$list' list"
    }            
  }
  foreach($ct in $web.ContentTypes) {
     $fieldInUseCt = $ct.FieldLinks | Where {$_.Id -eq $fieldId }
     if($fieldInUseCt) {
        Write-Host "'$web' web - Found a match in the '$field' field in the '$ct' Contenttype"
     }
  }
}