Monday, June 18, 2012

SharePoint 2010 - Creating a Site Collections By PowerShell

I found a blog, there are scripts for creating Farm, Web Application, Site Collection: http://blog.brianbeach.com (all credits to Brian). I want to write it here, like a reminder for myself. In addition, I think that the sharing knowledge is a best way to help to each other.

List of common templates:
  • STS#0 - Team Site
  • STS#1 - Blank Site
  • STS#2 - Document Workspace
  • MPS#0 - Basic Meeting Workspace
  • MPS#1 - Blank Meeting Workspace
  • MPS#2 - Decision Meeting Workspace
  • MPS#3 - Social Meeting Workspace
  • MPS#4 - Multipage Meeting Workspace
  • WIKI#0 - Wiki
  • BLOG#0 – Blog


  • $SiteName = "Human Resources Site"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com/sites/hr"
    $SiteTemplate = "STS#0"

    Write-Host "Creating a relative site collection in the intranet web application"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()



    $WebAppURL = "http://intranet.DOMAIN.com"
    $ContentDatabase = "Content_Intranet_BLOG"

    Write-Host "Creating a new content database in the intranet web application"
    New-SPContentDatabase $ContentDatabase -WebApplication $WebAppURL

    $SiteName = "Intranet Blog"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $SiteURL = "http://intranet.DOMAIN.com/sites/blog"
    $SiteTemplate = "BLOG#0"

    Write-Host "Creating a relative site collection in the intranet web application with a separate content database"
    New-SPSite -Url $SiteURL -owneralias $OwnerAlias -ownerEmail $OwnerEmail -ContentDatabase $ContentDatabase -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()



    $SiteName = "Intranet WIKI"
    $OwnerEmail = "USER_NAME@DOMAIN.com"
    $OwnerAlias = "DOMAIN\USER_NAME"
    $WebAppURL = "http://intranet.DOMAIN.com"
    $SiteURL = "http://wiki.DOMAIN.com"
    $SiteTemplate = "WIKI#0"

    Write-Host "Creating a hostheader site collection in the intranet web application"
    $WebApp = Get-SPWebApplication $WebAppURL
    New-SPSite -url $SiteURL -HostHeaderWebApplication $WebApp -owneralias $OwnerAlias -ownerEmail $OwnerEmail -Template $SiteTemplate
    $Web = Get-SPWeb $SiteURL
    $Web.title = $SiteName
    $Web.update()

    $WebAppName = "Intranet Web Application"
    $HostHeader = "wiki.DOMAIN.com"

    Import-Module WebAdministration
    New-WebBinding -Name $WebAppName -Port 80 -Protocol "http" -HostHeader $HostHeader

    No comments:

    Post a Comment