I need to find out custom site columns and custom site content types used in the client SharePoint applications.
I want to list down those using SharePoint 2013 PowerShell.
Please help me on this.
I think in order to get the custom columns or custom content type from SharePoint - we should know the unique identifier like a custom column group name - and using that "group name" we can get all columns belongs to that group.
OR
While exporting the SharePoint columns and content type to CSV file we can exclude the system related inbuilt columns and content type - then the exported result we can say as custom column and content type.
Sample script to get column details:
function GetSPFieldDetailsForAllLists($SiteCollectionURL)
{
$site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL) #Change site URL#
$web = $site.openweb()
foreach ($list in $web.Lists) #Get all list in web
{
foreach ($view in $list.Views) #Get all views in lists
{
$spView = $web.GetViewFromUrl($view.Url) #Grab views URL
Write-Host "List Name: " $list.Title ##Print List title
Write-Host "------------------------------------------------------"
Write-Host "Field Name | Field Title " -ForegroundColor DarkGreen
Write-Host "------------------------------------------------------"
foreach ($spField in $spView.ViewFields) #Loop through all view URLs and get Fields (columns)
{
foreach ($field in $list.Fields) #Get all fields in lists
{
if($spField -eq $field.Title) #if field in lists equals field in views
{
Write-Host $spField " | " $field.Type -ForegroundColor Green #Write out each field (column)
}
}
}
Write-Host "------------------------------------------------------"
Write-Host " "
}
}
$web.Dispose()
$site.Dispose()
}
Reference:
SharePoint: Get SPField details for SharePoint Lists using PowerShell
While exporting the columns details to CSV - we can exclude the below columns group:
#BlackList Group Names
#These are the known groups you get in a non publishing team site:
$blackList = @(
"_Hidden",
"Base Columns",
"Content Feedback",
"Core Contact and Calendar Columns",
"Core Document Columns",
"Core Task and Issue Columns",
"Custom Columns",
"Display Template Columns",
"Document and Record Management Columns",
"Enterprise Keywords Group",
"Extended Columns",
"JavaScript Display Template Columns",
"Reports",
"Status Indicators"
)
For details refer to the below:
Extract custom columns and their related values
Export SharePoint Content Type using PowerShell example
Get the Source Web
$SourceWeb = Get-SPWeb "http://dev.crescent.com"
#Create Export XML File
$XMLFile = "C:\SiteContentTypes.xml"
New-Item $XMLFile -type file -force
#Wrap Content Type Schema XML inside <ContentTypes> Element
Add-Content $XMLFile "`n<ContentTypes>"
#Export All Content types of specific Group to XML file
$sourceWeb.ContentTypes | ForEach-Object {
if ($_.Group -eq "Crescent Content Types")
{
#Export Content Types to XML file
Add-Content $XMLFile $_.SchemaXml
}
}
#Closing Wrapper
Add-Content $XMLFile "</ContentTypes>"
#Dispose the web object
$SourceWeb.Dispose()
Reference: