Get Content Type Fields using PowerShell in SharePoint

Requirement: PowerShell to get content type fields in SharePoint.

SharePoint PowerShell to Get Content Type Fields

Here is my PowerShell to get a Content Type and its columns, loop through them, and output a CSV file with the following data:

  • Column Title
  • Column Internal Name
  • Column ID
  • Column Group
  • Column Description
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Variables for processing
$SiteURL = "https://intranet.crescent.com"
$ContentTypeName = "Credit Projects"
$OutputFile = "C:\Temp\ContentTypes.csv"

#Get the Web
$Web = Get-SPWeb $SiteURL

#Get the Content Type
$CType = $Web.ContentTypes[$ContentTypeName] 

$ResultArray = @()
#Loop through the Fields in the Content Type
ForEach ($Field in $CType.Fields)
{
    # Create a new custom object to hold our row of data with property names:
    $Result = New-Object PSObject
    $Result | Add-Member -MemberType NoteProperty -Name "Title" -Value $field.Title
    $Result | Add-Member -MemberType NoteProperty -Name "Internal Name" -Value $field.InternalName
    $Result | Add-Member -MemberType NoteProperty -Name "ID" -Value $field.Id
    $Result | Add-Member -MemberType NoteProperty -Name "Group" -Value $field.Group
    $Result | Add-Member -MemberType NoteProperty -Name "Description" -Value $field.Description

    #Add the object to array
    $ResultArray += $Result
}

# Export the results to CSV
$ResultArray | Export-Csv $OutputFile -NoTypeInformation

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *