Pages

Search This Blog

Tuesday, June 14, 2011

Creating a web application and site collection using powershell scripts : SharePoint 2010

Hi,

Often, we come across requirements where we have to do some stuff on the staging or the production servers again and again like creating web applications/site collections in a fresh deployment.

Powershell is of great use here.It allows administrators to write scripts which can do all these tasks quickly.In this blog, I have provided powershell scripts that automate creation of a Sharepoint web application and a site collection.

The script to create a web application is as follows:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
$name = "Sharepoint 2010 test web application"
$port = 4444
$hostHeader = "Sharepoint2010Tricks.com"
$url = "http://sharepoint2010tricks.com/"
$appPoolName = "SharePoint-4444"
$appPoolAccount = Get-SPManagedAccount "<Your Domain>\<account name>"New-SPWebApplication -Name $name -Port $port -HostHeader $hostHeader -URL $url -ApplicationPool $appPoolName -ApplicationPoolAccount $appPoolAccount

Once the web application has been created , powershell will display the web application url as shown below:


Perform an iisreset now so that sharepoint detects the new web application.

After this , in order to create a site collection,run the following script:

$title= "Sharepoint 2010 test site"
$url = "http://sharepoint2010tricks.com:4444/"
$owner = "<Your Domain>\<account name>"
$template = "STS#1"
New-SPSite -URL $url -Name $title -OwnerAlias $owner -Template $template

The result will be the site collection url as shown below:

No comments:

Post a Comment