SharePoint 2010 Powershell Scripting: Unattended WebApp Install
We are getting to the point where we really need to crank out install after install here for different testing scenarios, so I’ve spent some more time creating some pretty easily customizable scripts to complete our installs, plus my eye was twitching as I referred to when I used PowerShell to install SharePoint 2010.
The first step was to get the Web application setup. The command to do this is New-SPWebApplication. If you do a help New-SPWebApplication-examples it will show you the general use of this command. However, keep in mind that there is a typo here. –HostHeader "http://sharepoint.dmz.contoso.com" won’t work; you will need to remove the http://.
help New-SPWebApplication NAME New-SPWebApplication SYNOPSIS Creates a new Web application within the local farm. ------------------EXAMPLE----------------------- C:\PS>New-SPWebApplication -Name "Contoso Internet Site" -Port 80 -HostHeader "http://sharepoint.dmz.contoso.com" –URL https://www.contoso.com" -ApplicationPool "ContosoAppPool" -ApplicationPoolAccount (Get-SPManagedAccount "DOMAIN\jdoe")
The preceding example creates a new Web application by using an internal host header of sharepoint.dmz.contoso.com and a public URL of https://www.contoso.com.
Below is my PowerShell script to create a Web application on SharePoint 2010. It’s pretty simple compared to the server-farm setup Web app install, and I will follow this with a site collection setup script once I get that cleaned up. The only settings you should need to modify are the farm variables. Just match them to the fields listed in Central Admin in the attached screen shots.
#Include the SharePoint cmdlets Add-PsSnapin Microsoft.SharePoint.PowerShell #Include the SharePoint cmdlets Add-PsSnapin Microsoft.SharePoint.PowerShell #Set the farm variables $sp_webapp_name = "2010 test web app" $sp_webapp_port = 80 $sp_webapp_hostheader = "sp2010test1.sharepointspace.com" $sp_webapp_url = "http://sp2010test1.sharepointspace.com" $sp_webapp_apppool = "sp2010AppPool" $sp_webapp_apppoolaccount = "testdomain\11_SP_Farm" $sp_webapp_databasename = "MySP_WebApp" $sp_webapp_databaseserver = "MySQLServer\InstanceName" #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 (Get-SPManagedAccount $sp_webapp_apppoolaccount) -DatabaseName $sp_webapp_databasename -DatabaseServer $sp_webapp_databaseserver
Why do you do the include twice?
01.#Include the SharePoint cmdlets
02.Add-PsSnapin Microsoft.SharePoint.PowerShell
03.#Include the SharePoint cmdlets
04.Add-PsSnapin Microsoft.SharePoint.PowerShell
Where can I find out how to bundle these into an executable batch file?
JK
The code tagging on this rev of the blog does some funny things. You only need to call it once.
http://technet.microsoft.com/en-us/library/ee176949.aspx
There is some info there about calling powershell cmdlets from a command line. You should be able to take that and wrap it into a batch file easy enough.
I actually wrote a blog on how to add the snap-ins (actually the SQL plug-ins, but the same principle should apply here) without any red alerts (if they’re already added) here:
http://blog.webtechy.co.uk/blog/_archives/2010/7/7/4572685.html
Chris, I’d be interested in talking with you with regards to having a reseller package with you guys, and enabling a sign-up process where a site is provisioned for them automatically (hence why I came across this blog).
Many thanks.
Hey,
I would like to ask you how to give a domain user account for $sp_webapp_apppoolaccount = “testdomain\11_SP_Farm”
I think first the “testdomain\11_sp_farm” account should be added to the Saherpoint as an SPprocessaccount.. but how to do that? if you use the farmadmin account for appool, the sharepoint health service will cry ‘cos of security reasons (do not use farm admin account as an app pool service account)
thanks for replying, BR, Adam
OK.. got the new-SPManagedAccount command