Finding Custom Columns in SharePoint

As we're looking to remove a third-party component from our farm, I looked to find where it may have a presence in our lists. This script helped us look through the lists and get suspect columns. While looking at the columns through the browser shows the column types appropriately, PowerShell shows the types as "invalid". Thus, this is a less than ideal script (that includes the bad loops as well).


function GetAllWebs($url){
    $spWeb = Get-SPWeb $url;
    if($spWeb.Webs.Count -gt 0)
    {
        ForEach($web in $spWeb.Webs)
        {
            $web
            GetAllWebs $web.Url;
        }
    }
}


$allWebs = getallwebs("https://localhost")

function getInvalids(){

    ForEach($web in ($allwebs | where { $_.url.length -gt 0 }) ){
  
    
            ForEach($list in $web.Lists){
               $isListBamboo = $false

                ForEach($field in  $list.Fields){
                
                    if($field.type -match "Invalid"){
                        $isListBamboo = $true
                        break
                    }
                }
                if($isListBamboo){
                    $data = [pscustomobject]@{
                        url = $web.Url
                        listTitle = $list.title
                    }
                    write-host $data
                    Write-Output $data
                }
              
            }
    }
}

getinvalids | export-csv -Path "C:\\temp\\invalids.csv"

You may also like