Visualize yourself the scenario were you are about to set up a SharePoint environment containing a lot of Web Applications and that some of them needs to be extended both two and three times. Add to that, that you need to set it up in a Test, QA and a production environment and in the same way have a good recovery plan for setting them up again in case of a disaster.

In 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 script where we use a input file as source. In this case I decided to use Excel, so it’s easy to fill in all info on your Web Applications in an Excel file. By using a macro you can then by pushing a button in Excel generate a xml-config and that’s the one to use as input for your PowerShell script.

First, let me introduce the Config Generator. This is an excel file where you fill in the info on the Web Applications that you want to set up. Below is a list of all the settings you fill in, in the Excel sheet. One Web Application or extend of Web Application per row.

Setting Value Example
Type New/Extend (drop down)  New
Extend  url of site to extend if applicable  http://portalsite.com
WebAppDisplayName  Used e.g. in IIS  The Portal site
WebAppHostHeader  the url of the site  portalsite.com
LoadBalancerURL  The load balancer url  http://portalsite.com
WebAppPort  Port to use  80
SSL  true/false (drop down)  false
AllowAnynomousAccess  true/false (drop down)  false
Zone  Default/Internet/Extranet/Intranet/Custom (drop down)  Default
WebAppContentDBName  Name of the content database  WebApp_PortalSite_01
WebAppPoolName  IIS Application pool to use.  Portalsite
WebAppPoolUsername  Username to use as identity of Application Pool, if applicable  Username
WebAppPoolPassword  Password for the Application Pool identity account  Password
DatabaseServer  Database server to use  SQLsrv01
ISSRootDirectory  File path to your IIS root directory  c:\inetpub\wwwroot\…

As you can see you have a couple of fields related to the IIS Application Pool. What the script does is that, if you have filled in the WebAppUsername the Application Pool will be created with the new credentials. If you leave the WebAppUsername blank it assumes that the Application Pool exist and connects the site to that Application Pool.

You will also find columns to insert Site Collection information. This info will be put into the config file as well and used for creating the root Site Collection of your new Web Application. The following settings are available:

Setting Value Example
Title Title of the site Start page
Description Description of the site This is the start page for the Sales organisation
Template The template name to use. To view existing templates
an their name check this article
STS#1
Admin AD-account of who should be owner of the site  AD\username
AdminName  The display name of the admin  Mattias Karlsson
AdminEmail The e-mail address of the admin Mattias.Karlsson@nima.com

When you have filled in the info on all your Web Applications just push the Generate Config File button and Excel will generate a config.xml file in the same folder as the Excel file is located in.

ConfigGenerator

What you then need to do is to copy the config.xml to the server along with the CreateWebApps.ps1 file.

Open up the PowerShell command shell, include the file CreateWebApps.ps1 file by typing:

. ./CreateWebApps.ps1

Then you call the function by typing:

SP-WebAppBuilder -ConfigPath [path]\config.xml

This will now generate all your Web Applications as you have specified in the Excel-file so go grab yourself some coffee and let the script handle the rest.

The above example is an teaser of what will be covered in the coming book SharePoint and PowerShell – In real life that I together with Niklas Goude is writing. The code can be found in the download section.



  1. Tony Parmstig on Tuesday 8, 2009

    Thanks for Sharing! god job last night!



Subscribe without commenting