Written by 7:00 pm Microsoft, Office 365, PowerShell, Windows Server • 16 Comments

Powershell: Create a new Sharepoint 2010 WebApplication and Site collection

Powershell Header

Microsoft Sharepoint 2010 is one of the new products which supports Windows Powershell commands. Its really easy to do the most tasks you do normally in the Sharepoint Central Administration with PowerShell.

Microsoft created a PowerShell Snapin for Sharepoint 2010, which is called “Microsoft.Sharepoint.Powershell”. This enables a lot of new PowerShell cmdlets for Sharepoint.

With this small scripts you can simply create a new WebApplication and/or a new Sharepoint Site Collection.

Add the Sharepoint cmdlets:

Add-PsSnapin Microsoft.SharePoint.PowerShell

Help for creating a new Sharepoint WebApplication:

The Powershell command for creating a new Web Application is New-SPWebApplication.

Get-Help New-SPWebApplication
NAME
New-SPWebApplication
 
SYNOPSIS
Creates a new Web application within the local farm.
 
SYNTAX
New-SPWebApplication -ApplicationPool  -Name  [-AdditionalClaimProvider <SPClaimProviderPipeBind[]>
] [-AllowAnonymousAccess ] [-ApplicationPoolAccount ] [-AssignmentCollec
tion ] [-AuthenticationMethod ] [-AuthenticationProvider ] [-Confirm []] [-DatabaseCredentials ] [-DatabaseName ] [-Databas
eServer ] [-HostHeader ] [-Path ] [-Port ] [-SecureSocketsLayer ]
[-ServiceApplicationProxyGroup ] [-SignInRedirectProvider ] [-SignInRedirectURL ] [-Url ] [-WhatIf []] []
 
DESCRIPTION
Creates a new Web application specified by the Name parameter. The user specified by the DatabaseCredentials parame
ter must be a member of the dbcreator fixed server role on the database server.
 
For permissions and the most current information about Windows PowerShell for SharePoint Products, see the online d
ocumentation (http://go.microsoft.com/fwlink/?LinkId=163185).
 
RELATED LINKS
Get-SPWebApplication
Set-SPWebApplication
Get-SPWebApplication
 
REMARKS
To see the examples, type: "get-help New-SPWebApplication -examples".
For more information, type: "get-help New-SPWebApplication -detailed".
For technical information, type: "get-help New-SPWebApplication -full".

Creating a new Sharepoint WebApplication:

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Set variables
$WebAppName = "Contoso Sharepoint1"
$WebAppHostHeader = "sharepoint1.contoso.com"
$WebAppPort = 80
$WebAppAppPool = "SharePoint1AppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "contoso\sp_serviceuser"
$WebAppDatabaseName = "Sharepoint1"
$WebAppDatabaseServer = "SQLServer\InstanceName"
 
# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WWebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer

Creating a new Sharepoint Site Collection:

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Templates
# Name Title LocaleId Custom
# ---- ----- -------- ------
# GLOBAL#0 Global template 1033 False
# STS#0 Team Site 1033 False
# STS#1 Blank Site 1033 False
# STS#2 Document Workspace 1033 False
# MPS#0 Basic Meeting Workspace 1033 False
# MPS#1 Blank Meeting Workspace 1033 False
# MPS#2 Decision Meeting Workspace 1033 False
# MPS#3 Social Meeting Workspace 1033 False
# MPS#4 Multipage Meeting Workspace 1033 False
# CENTRALADMIN#0 Central Admin Site 1033 False
# WIKI#0 Wiki Site 1033 False
# BLOG#0 Blog 1033 False
# SGS#0 Group Work Site 1033 False
# TENANTADMIN#0 Tenant Admin Site 1033 False
 
# Languages
# Name Title
# ---- -----
# German 1031
# English 1033
# French 1036
# Spanish 1034
 
# Set variables
$SiteCollectionName = "Homepage"
$SiteCollectionURL = "http://sharepoint.contoso.com"
$SiteCollectionTemplate = "STS#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "contoso\UserName"
 
# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Creating a new Sharepoint WebApplication and a Sharepoint Site Collection:

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Set variables
$WebAppName = "Contoso Sharepoint1"
$WebAppHostHeader = "sharepoint1.contoso.com"
$WebAppPort = 80
$WebAppAppPool = "SharePoint1AppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "contoso\sp_serviceuser"
$WebAppDatabaseName = "Sharepoint1"
$WebAppDatabaseServer = "SQLServer\InstanceName"
$SiteCollectionName = "Homepage"
$SiteCollectionURL = ("http://" + $WebAppHostHeader)
$SiteCollectionTemplate = "STS#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "contoso\UserName"
 
# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer
 
# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Tags: , , , , , , , , , , , , , Last modified: July 5, 2019
Close Search Window
Close