title: Powershell Script to get all columns and type in a SPList
body: <p>I want to retrieve all columns, and their type in a SharePoint list.
  I have tried several scripts but the results are not what I am looking for.</p>
  
  <p><a href="https://i.stack.imgur.com/2Ekf0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Ekf0.png" alt="enter image description here"></a></p>
  
  <p>Below are the scripts I have tried:</p>
  
  <pre><code>Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
  #Configuration Parameters
  $SiteURL="http://url.com/"
  $ListName= "theList"
  $CSVPath="C:\Temp\list.csv"
  
  #Get the Web and List
  $Web = Get-SPWeb $SiteURL
  $List = $Web.Lists.TryGetList($ListName)
  
  #Export List Fields to CSV file
  $List.Fields | select Title, InternalName | Export-Csv -path $CSVPath -NoTypeInformation
  </code></pre>
  
  <hr>
  
  <pre><code>Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
  $url = "http://url.com/"
  $listName = "theList"
  $path ="C:\Temp\list.csv"
  
  $web = Get-SPWeb $url
  $list = $web.Lists.TryGetList($listName)
  $fields = $list.ContentTypes | %{ $_.FieldLinks }
  $items = @() #array to store objects representing list items
  $list.items | %{ 
      $item = $_; 
      $hash = @{}; #hash table to store field name-value pairs
      $fields | %{ $hash[$_.DisplayName] = $item[$_.Name]  }; 
      $items += new-object psobject -Property $hash }
  $items | Export-Csv -Path $path
  </code></pre>