Author Posts

January 1, 2012 at 12:00 am

by bronyx85 at 2013-02-25 08:19:34

Hi,

by AlexBrassington at 2013-02-25 08:48:39

Right sort of approach.

It's worth mentioning that you're not after Sites here, you're after Webs (SPWebs to be precise). Apologies if you're just using short hand but it may be that you would benefit from a bit of time looking at the Object Model. It's a very complicated beast in SharePoint but you'll never be able to write good PowerShell without knowing it.

#
$SPSite = Get-SPSite "http://webapp.domain.com/sites/sitecollection"
$DocumentLibraryName = "Jumper Documents"

#For each web in the site collection (Note: I don't know if this is recursive)
$SPSite.Webs | % {
#Get the library
$library = $_.Lists[$DocumentLibraryName]

#Check the library really does exist
if ($Library -ne $null)
{
#Library does actually exist! Enable content types
$Library.ContentTypesEnabled = $true
Write-OutPut "Updated $DocumentLibraryName document library on site $($_.URL)"

#Update the library
$Library.Update()
}
}
#Dispose of the SiteCollection object.
$SPSite.Dispose()

That might do the job. I haven't tested it, i'm re-building my dev farm, but it should be 95% of the way there. I'm not sure if that will get all the subsites (i.e. subsubsites etc.) in which case you'll need to go for a recursive call or find a recursion flag.