PowerShell script create WebApp and Site Collection SharePoint 2010

With the following powershell script you can build webapplications and site collections in SharePoint 2010:

#Include the SharePoint cmdlets
#Add-PsSnapin Microsoft.SharePoint.PowerShell

do
{
#user input and set farm variables
Write-Host ‘Create SharePoint 2010 Web application and Site Collection’
Write-Host ‘———————————————————-’
Write-Host ‘First Enter some variables’

$sp_webapp_name = read-host -prompt ‘Web application name:’
$sp_webapp_port = read-host -prompt ‘Web application port:’
$sp_webapp_hostheader = read-host -prompt ‘Web application host header:’
$sp_webapp_url = ‘http://’ + $sp_webapp_hostheader
$sp_webapp_apppool = read-host -prompt ‘Web application pool name:’
$sp_webapp_apppoolaccount = read-host -prompt ‘Web application pool account:’
$sp_webapp_databasename = read-host -prompt ‘Web application pool database name:’
$sp_webapp_databaseserver = read-host -prompt ‘Web application database server name:’

#Create a new Web Application
new-spwebapplication -name $sp_webapp_name -Port $sp_webapp_port -HostHeader $sp_webapp_hostheader -URL $sp_webapp_url -ApplicationPool $sp_webapp_apppool -ApplicationPoolAccount $sp_webapp_apppoolaccount -DatabaseName $sp_webapp_databasename -DatabaseServer $sp_webapp_databaseserver

Write-Host ‘Web application is configured’
$strContinue = read-host -prompt ‘Continue creating a Site Collection? (Y/N)’
if ($strContinue -eq ‘Y’){

# Create SharePoint 2010 Site Collection
# base template values

Write-Host ‘Create SharePoint 2010 Site Collection:’
Write-Host ‘ Name                 Title                                    LocaleId   Custom’
Write-Host ‘ ——                 —-—–                                    ——–       –——’
Write-Host ‘ GLOBAL#0             Global template                          1033       False’
Write-Host ‘ STS#0                Team Site                                1033       False’
Write-Host ‘ STS#1                Blank Site                               1033       False’
Write-Host ‘ STS#2                Document Workspace                       1033       False’
Write-Host ‘ MPS#0                Basic Meeting Workspace                  1033       False’
Write-Host ‘ MPS#1                Blank Meeting Workspace                  1033       False’
Write-Host ‘ MPS#2                Decision Meeting Workspace               1033       False’
Write-Host ‘ MPS#3                Social Meeting Workspace                 1033       False’
Write-Host ‘ MPS#4                Multipage Meeting Workspace              1033       False’
Write-Host ‘ CENTRALADMIN#0       Central Admin Site                       1033       False’
Write-Host ‘ WIKI#0               Wiki Site                                1033       False’
Write-Host ‘ BLOG#0               Blog                                     1033       False’
Write-Host ‘ SGS#0                Group Work Site                          1033       False’
Write-Host ‘ TENANTADMIN#0        Tenant Admin Site                        1033       False’

$sp_sc_template = read-host -prompt ‘Site Collection template name:’
$strSameWebApp = Read-Host ‘Use same webbapplication you have just created? (Y/N)’
if ($strSameWebApp -eq ‘Y’) {$sp_sc_webappurl = ‘http://’ + $sp_webapp_name}
else {$sp_sc_webappurl = read-host -prompt ‘Site Collection webbapplication:’}
$sp_sc_name = read-host -prompt ‘Site Collection name:’
$sp_sc_language = read-host -prompt ‘Site Collection language LocaleId:’
$sp_sc_owner = read-host -prompt ‘Site Collection owner (DOMAINUSERNAME):’
new-SPSite -url $s p _sc_webappurl -OwnerAlias $sp_sc_owner -Language $sp_sc_language -Template $sp_sc_template -Name $sp_sc_name
}
# Create another Webapp and Site Collection? if yes, start all over again.
$strResponse = Read-Host ‘Do you want to Create another Webapp and Site Collecion? (Y/N)’
}

# if no, than quit the ps script
until ($strResponse -eq ‘N’)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>