Installing and Configuring SharePoint 2010 through Powershell

Installing and Configuring SharePoint 2010 through Powershell Scripting

STEP1: Preparation

Download the SPModule and add the same folder location to the PSModulePath in Environmental variables of respective server as shown below:

 

 

#Restart the server before installing SP2010

Restart-Computer -force

 

STEP2: Installation. I have named this file as SP1.PS1.

====================================
SP1.ps1 [ PowerShell -File "SP1.ps1" ]

====================================

#Run the below script to install the pre-requisite and SharePoint binaries

Set-ExecutionPolicy Unrestricted -Force

Import-Module SPModule.misc

Import-Module SPModule.setup

Install-SharePoint -SetupExePath "C:SP2010Extractsetup.exe"

#Above is for the trail version so for license version PIDKey needs to be included as bellow

#Install-SharePoint -SetupExePath "C:SP2010Extractsetup.exe" -PIDKey "***************************************"

#Check if the installation is done properly by checking the services in service.msc

If (((Get-Service | Where {$_.Name -eq "SPAdminV4"}) -ne $null) -and ((Get-Service | Where {$_.Name -eq "SPTimerV4"}) -ne $null) -and ((Get-Service | Where {$_.Name -eq "FIMSynchronizationService"}) -ne $null))

{

Write-Host -foregroundColor Yellow "SharePoint 2010 installed successfully… `nNow the setup will configure the farm."

PowerShell -File "SP2.ps1"

}

Else

{

Write-Warning "SharePoint 2010 installation failed, please check the logs for the error."

}

STEP2: Configuration. I have named this file as SP2.PS1.

====================================
SP2.ps1

====================================

#Configure the farm

$DatabaseServer = "WIN2008SQLMyNewInstance"; #SPecify the instance name if SQL is not installed on default instance

$FarmName = "SPFarm";

$ConfigDB = $FarmName+"_ConfigDB";

$AdminContentDB = $FarmName+"_CentralAdminContent";

$Passphrase = convertto-securestring "P@ssW0rD!" -asplaintext -force;

$Port = "5000";

$Authentication = "NTLM";

# In PowerShell we can not pass the password hardcoded, so we need to get the password in a text file and then read it from that. And the password in the file will be saved in secure string format. That file needs to be saved on all the servers.

#read-host -assecurestring | convertfrom-securestring | out-file C:cred.txt

#The above command create a file and store the password in encrypted form. NOTE: THIS NEEDS TO BE DONE BEFORE YOU START THE STEP2.

$FarmAcct = "tailspintoysspinstall";

$FarmPassword = get-content C:cred.txt | convertto-securestring

$FarmCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $FarmAcct,$FarmPassword

if( (Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {

Add-PSSnapin Microsoft.SharePoint.PowerShell;

}

Write-Host -foregroundColor Yellow "Your SharePoint Farm is being configured..."

New-SPConfigurationDatabase -DatabaseName $ConfigDB -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDB -Passphrase $Passphrase -FarmCredentials $FarmCred

Write-Host -foregroundColor Yellow "Farm Configuration and Admin Content databases has been created successfully..."

#Installing the help files

Install-SPHelpCollection -All

# Securing the files and registry entries on the server

Initialize-SPResourceSecurity

# Installing services

Install-SPService

# Installing SPFeatures

Install-SPFeature –AllExistingFeatures

# Installing all of the application content

Install-SPApplicationContent

# Provisioning Central Admin

New-SPCentralAdministration -Port $Port -WindowsAuthProvider $Authentication

# Adding new Managed Account to the farm

$ManagedAcct = "tailspintoysSPWebAC";

$ManagedPassword = get-content C:cred.txt | convertto-securestring # We are using the same file that was used for farm credential considering that both the accounts has same password

$ManagedCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $ManagedAcct,$ManagedPassword

New-SPManagedAccount -Credential $ManagedCred

 

#Managed account for SPSearch service

$ManagedAcct = "tailspintoysSPCrawl";

$ManagedPassword = get-content C:cred.txt | convertto-securestring

$ManagedCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $ManagedAcct,$ManagedPassword

New-SPManagedAccount -Credential $ManagedCred

 

#Creating a Web Application

$WebName="SPWeb-1"

$Port="90"

$URL="https://win2008sql"

$DatabaseServer= "WIN2008SQLMYNEWINSTANCE"

$DatabaseName= $FarmName + "_" + $WebName + "_ContentDB"

$AppPoolAC="tailspintoysSPWebAC" #Ensure that AppPoolAC account has been already added as Managed Account.

New-SPWebApplication -Name $WebName -Port $Port -Url $URL -ApplicationPool $WebName -ApplicationPoolAccount (Get-SPManagedAccount $AppPoolAC) -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName

 

#Creating a Web Application with HostHeader

$WebName="SPWeb-2"

$Port="80"

$URL="https://LV.tailspintoys.com"

$DatabaseServer= "WIN2008SQLMYNEWINSTANCE"

$DatabaseName= $FarmName + "_" + $WebName + "_ContentDB"

$AppPoolAC="tailspintoysSPWebAC"  # Ensure that AppPoolAC account has been already added as Managed Account.

$HostHeader="LV.tailspintoys.com"

 

New-SPWebApplication -Name $WebName -Port $Port -Url $URL -ApplicationPool $WebName -HostHeader $HostHeader -ApplicationPoolAccount (Get-SPManagedAccount $AppPoolAC) -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName

 

#Creating Site Collection:

$SiteURL="https://win2008sql:90/sites/Team"

$SiteAdmin="tailspintoysSPSiteAC"

$Title="Root Site"

$Template="STS#0"

New-SPSite $SiteURL -OwnerAlias $SiteAdmin -Name $Title -Template $Template

#Starting the SPSearch - MSF search

$svc = Get-SPServiceInstance | where {$_.TypeName -eq "SharePoint Foundation Search"}

Start-SPServiceInstance -Identity $svc

$SearchCrawl = "tailspintoysSPCrawl";

$SearchPassword = get-content C:cred.txt | convertto-securestring

Set-SPSearchService -CrawlAccount $SearchCrawl -CrawlPassword $Searchpassword

#Starting the Usage Analysis

New-SPUsageApplication –Name “SharePoint Usage Application Service” –DatabaseName “SP2010_Usage”