kwizcom banner advertisement

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 = "http://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
Get Content Type Fields using PowerShell in SharePoint Get Content Type Fields using PowerShell in SharePoint Reviewed by Salaudeen Rajack on May 28, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.