Here is a simple script for creating a new Web Application in SharePoint. This will be the first out of a series of post on the topic were we will go through creating, extending and finally give you a script to automate the creation and extending multiple Web Applications with root site collections. Very useful in disaster and recovery scenarios or when you have a lot of Web Apps that you need to create in the same way on different staging environments.
So, start of with the usual connection to the farm:
$farm = [microsoft.sharepoint.administration.spfarm]::local
We then create a new SPWebApplicationBuilder object and add the settings we want. Note that you need to change the values below to your own values. The values are quite self-explanatory so I will not go through all of them.
$WebAppBuilder.ApplicationPoolId = “SharePoint_TestFarm_WebApp”
$WebAppBuilder.ApplicationPoolUsername = “Domain\AppPoolUserNameUsername”
$WebAppBuilder.ApplicationPoolPassword = “AppPoolPassword”
$WebAppBuilder.Port = 8080
$WebAppBuilder.ServerComment = “New WebApp”
$WebAppBuilder.CreateNewDatabase = $true
$WebAppBuilder.DatabaseServer = “DEVWSS\Microsoft##SSEE”
$WebAppBuilder.DatabaseName = “TestFarm_ContentDB_01″
$WebAppBuilder.RootDirectory = “C:\Inetpub\wwwroot\wss\VirtualDirectories\NewWebApp”
$WebAppBuilder.UseSecureSocketsLayer = $false
$WebAppBuilder.AllowAnonymousAccess = $false
$webapp = $WebAppBuilder.Create()
$webapp.Provision()
In the script above I use the ApplicationPoolId. If you type a name of a application pool that does not exist it will be created and you will need the ApplicationPoolUsername and ApplicationPoolPassword. If you want to share Application Pool you skip the username and password and type the existing Application Pool Name.
We then end with the Create() and the Provision().
If you have a farm with more then one Web Front End Server you will need to add the below lines to make sure that the ApplicationPoolUsername and Password is deployed to the other WFEs. In that case, skip the ApplicationPool Username and Password above. You will also need to replace the Provision() with ProvisionGlobally.
$webapp.ApplicationPool.Password = “AppPoolPassword”
$webapp.ApplicationPool.Update()
$webapp.ApplicationPool.Deploy()
That’s about it. In part two we will look into how we can extend our new Web Application.









[...] two earlier posts I have written about how to create and extend a web application using PowerShell. Today I ran in to a problem when I extended a Web [...]
[...] two earlier posts I have written about how to create a Web Application and how to extend a Web Applicationusing PowerShell. Now it’s time to combine the two into one [...]