Wednesday, July 25, 2012
PowerShell script to add "Link to a Document" content type to all document libraries
$linkct = "Link to a Document"
$docct = "Document"
Get-SPSite -Limit all | Get-SPWeb -Limit all | ForEach-Object {
$doclibtype =[Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$doclibs = $_.GetListsOfType($doclibtype)
foreach ($doclib in $doclibs)
{
$newdoclib = $_.Lists[$doclib.ID]
if ($newdoclib.AllowContentTypes)
{
$newdoclib.ContentTypesEnabled = $true
$newdoclib.Update()
#Add site content types to the list
if (($newdoclib.ContentTypes[$linkct] -eq $null) -and
($newdoclib.ContentTypes[$docct] -ne $null))
{
$ctToAdd = $_.Site.RootWeb.ContentTypes[$linkct]
$ct = $newdoclib.ContentTypes.Add($ctToAdd)
"Content type " + $ct.Name + " added to list " + $newdoclib.Title
$newdoclib.Update()
}
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment