SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way that I can create a web application, site collection and sites using poweshell and batch file automatically? So, User has to click on executable batch file which will create the web application on port 80 with content database written in powershell, site collection and 10 sub sites into it?

In my case the user doesn't know how to create a Sharepoint site. They just want to double click on file and the work is done!

share|improve this question
up vote 0 down vote accepted

You could use the following cmdlets to accomplish this:




On each step, just assign to a variable so you can use it in the next cmdlet.

Using the examples from the articles, you could do:

$ap = New-SPAuthenticationProvider
$webApp = New-SPWebApplication -Name "Contoso Internet Site" -Port 80 -HostHeader -URL "" -ApplicationPool "ContosoAppPool" -ApplicationPoolAccount (Get-SPManagedAccount "DOMAIN\jdoe") –AuthenticationProvider $ap -SecureSocketsLayer
$site = New-SPSite -OwnerAlias "DOMAIN\jdow" -HostHeaderWebApplication $webApp -Name "Contoso" -Template "STS#0"
New-SPWeb http://somesite/subweb1 -Template "STS#0"
share|improve this answer
Thanks but can you explain me with example? – user15099 Feb 22 '13 at 21:00
Added examples from the articles. – John Chapman Feb 22 '13 at 21:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.