Dan Sanders
  • Home
  • About
  • Contact
  • – PowerShell
  • – SharePoint
  • – Workflow
Copyright © 2016 Dan Sanders. All Rights Reserved.
Dan Sanders
  • Home
  • About
  • Contact
  • – PowerShell
  • – SharePoint
  • – Workflow

Adding a column to a Content Type (CT) at a library level with PowerShell.

byDan Sanders inPowershell, SharePoint posted10 February, 2016
67
0
Adding a column to a Content Type (CT) at a library level with PowerShell.

The reason you might want to do this is you may have a Choice column with different choice data in it in each library, but the column name is the same.
Adding the a Site Column at a global level to the CT will not put the unique options in the CT at each library. Adding the column from the library level, puts that libraries version of the column on the CT
The below code targets the 3rd level down of a particular site (Web), and goes through each Library to add the column to the Content Type.
If you need to update all libraries from a Site Collection level put the Try Catch statement in a different loop that iterates through each library (like in this post)

$site = Get-SPSite http://intranet
$Web = Get-SPWeb http://intranet/Web/
$Web.webs | ForEach-Object {
 $_.title # Web Name
 $_.webs.lists | where { $_.BaseTemplate -eq "DocumentLibrary" } | ForEach-Object {
 if($_.title -eq "Site Assets")
  {
   write-host "Skip Site Assets"
  }
  else
  {
   try
   {
         $fieldToAdd = $_.fields.getfield("Subactivity Groups")
         $fieldLink = new-object Microsoft.SharePoint.SPFieldLink($fieldToAdd)
         $CTtype = $_.ContentTypes["RDC_Link to document"]
         $CTtype.fieldlinks.add($fieldLink)
         write-host "updating" $_.title "..."
         $CTtype.Update()
         write-host $_.title "updated."
   }
   catch
   {
    write-host "Failed to add Content type" $ct.Name "to list" $_.Title
   }
  }
 }
}
$Site.Dispose()
$Web.Dispose()
Content TypesDocument LibrariesPowerShellSharePointSharePoint 2010SharePoint 2013
Share this :

Related Posts

0
24 June, 2013
Enable Fly-Out for Quick Launch

The reason you might want to do this is you may have a Choice column with different choice data...

96 Comments
0
Libraries with no Default View
27 January, 2016
Libraries with no Default View

The reason you might want to do this is you may have a Choice column with different choice data...

26 Comments
0
25 June, 2013
Deploying SharePoint 2010 Solutions with Powershell

The reason you might want to do this is you may have a Choice column with different choice data...

20 Comments
0
17 September, 2013
Remove Drop Off Library and fix up the QuickLaunch in SharePoint 2010

The reason you might want to do this is you may have a Choice column with different choice data...

67 Comments
0
4 February, 2016
Adding a ContentType to each Library with PowerShell

The reason you might want to do this is you may have a Choice column with different choice data...

30 Comments
0
PowerShell for every List in each Web of a SiteCollection
28 February, 2016
PowerShell for every List in each Web of a SiteCollection

The reason you might want to do this is you may have a Choice column with different choice data...

37 Comments
0
Creating a view for each Document Library in a Site Collection
3 February, 2016
Creating a view for each Document Library in a Site Collection

The reason you might want to do this is you may have a Choice column with different choice data...

135 Comments
0
24 June, 2013
Customizing the Quick Launch

The reason you might want to do this is you may have a Choice column with different choice data...

368 Comments
0
Associate your 2013 workflow to every library/list through PowerShell
29 February, 2016
Associate your 2013 workflow to every library/list through PowerShell

The reason you might want to do this is you may have a Choice column with different choice data...

No comment
2
SharePoint Foundation 2013 Shopping Cart
30 August, 2016
SharePoint Foundation 2013 Shopping Cart

The reason you might want to do this is you may have a Choice column with different choice data...

1 Comment

Leave a Comment! Cancel reply

You must be logged in to post a comment.

Recent Posts

  • SharePoint Add-in 401 Unauthorized
  • Content Database and Site Collection Report
  • SharePoint helpful hidden URLs

Tags

Config (1) Content Types (2) Design (3) Document Libraries (7) Document Sets (1) How-To (1) Lists (4) Office365 (1) PnP (1) PowerShell (12) Quick Edit (2) REST (1) SharePoint (11) SharePoint 2010 (11) SharePoint 2013 (14) SharePoint Foundation (2) SharePoint Online (1) SP2010 Workflow (2) SP2013 Workflow (3) Systems (2) User Profile Service (1) Views (5) Windows Server (1) Workflow (2)

Archives

  • November 2020
  • December 2018
  • September 2018
  • July 2018
  • September 2017
  • August 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • September 2013
  • July 2013
  • June 2013