Home > SharePoint > PowerShell Script to Create Web Application and Site Collection in SharePoint 2010

PowerShell Script to Create Web Application and Site Collection in SharePoint 2010


As we all know every time we want to create a web application in SharePoint we first have to create a new web application and then at the root of the application we have to create a site collection using SharePoint Site Collection templates.

If we just create a web application and try to access the site it will not show anything.

To combine the process I created this simple PowerShell script to do both at the same time.


——————————————–

# This script will create new Web Application and then create a new Site Collection

# Set Execution Policy

Set-ExecutionPolicy unrestricted

#Gather the web application and site collection variables

$Name = Read-Host(“Enter the name of Web Application”)

$DatabaseName = Read-Host(“Enter Database Name”)

$Port = Read-Host (“Enter the Port Number”)

$URL = Read-Host(“Enter the URL”)

$AppPoolName = Read-Host (“Enter the Application Pool Name”)

$AppPoolAcct = Read-Host (“Enter the Application Pool account Domain\user”)

$SiteName = Read-Host (“Enter the Name of Site Collection”)

$SiteURL = Read-Host (“Enter the Name of the Site Collection Url”)

$SiteOwner = Read-Host (“Enter the Site Collection Owner”)

$Template = Read-Host (“Enter the Site Template e.g. STS#0”)

# Create Web Application

function create_WebApp

{

New-SPWebApplication -Name $Name -Port $Port -URL $URL -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAcct -DatabaseName $DatabaseName

}

# Create Site Collection

function create_SiteCollection

{

New-SPSite $SiteURL -OwnerAlias $SiteOwner -Template $Template

}

if (create_WebApp)

{

Write-Host $URL

create_SiteCollection

}

else

{

Write-Host “Error”

}

if (create_SiteCollection)

{

Write-Host $SiteUrL

}

——————————————————————-

Thanks

Advertisements
Categories: SharePoint
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: