Finding Site with Powershell

Welcome Forums General PowerShell Q&A Finding Site with Powershell

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #6414

    Points: 0
    Rank: Member

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


    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 ""
    $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
    #Dispose of the SiteCollection object.

    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.

The topic ‘Finding Site with Powershell’ is closed to new replies.