Pages

Monday, July 23, 2012

Creating site collection and default SharePoint groups using PowerShell scripts – SharePoint 2010


I have used below PowerShell scripts which was creating web application and site collection. After digging into created site collection I have noticed that site don’t have any default SharePoint groups (i.e. Owners, Members, Reader, Visitors), that means my PowerShell scripts was not powerful enough to create default SharePoint groups :)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Add-PSSnapin Microsoft.SharePoint.PowerShell
# Set variables for New web application
$WebAppName = "Web Application Name" #name as it appears in central admin
$WebAppHostHeader = "webapplication.sharepoint.com  #host header name
$WebAppPort = 80  #port number fixed
$WebAppAppPool = "web app pool name"
$WebAppAppPoolAccount = "Application pool account" #web application pool account  This User has to be a SharePoint Manage Account
$WebAppDatabaseName = "SP2010_New_WebAppContent"   # database name
$WebAppDatabaseServer = "Database server name" # database server name
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer

# Set variables for creating new top level site collection
$siteCollectionUrl = "http://webapp.sp.com/sites/demo1"
$siteCollectionName = "Demo 1" #site collection name
$siteCollectionOwner1 = "ad\user1 " #site collection owner 1
$siteCollectionOwner2 = "ad\user2" #site collection owner 2
$siteCollectionTemplate = "STS#0" #site template - team site

## Create the site collection
New-SPSite -URL $siteCollectionUrl -OwnerAlias $siteCollectionOwner1 -SecondaryOwnerAlias $siteCollectionOwner2 -Name $siteCollectionName -Template $siteCollectionTemplate
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

So after searching little bit online, I have found two different links from which we can create web application, site collection with default SharePoint groups :)

Here are reference links:



Enjoy with PowerShell scripts :)

No comments:

Post a Comment