SharePoint Tech Blog


Create SharePoint Web Application and Root Site Collection using Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 10:58 am

PowerShell is a really powerful scripting tool and I’m quite amazed at how simple it is to automate several tasks in SharePoint using PowerShell. To start this blog off, here’s a simple script to create a web application using PowerShell:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
# Return the Default TimeZone for Sydney
function get-defaulttimezoneid
[Microsoft.SharePoint.SPregionalSettings]::Globaltimezones | where-object { $_.Description -like "*sydney*" }
$webAppBuilder=new-object Microsoft.SharePoint.Administration.SPWebApplicationBuilder( [Microsoft.SharePoint.Administration.SPFarm]::Local);
$webAppBuilder.ServerComment="SharePoint - $port";
$webAppBuilder.ApplicationPoolID="SharePoint - $port";
$webApp.ApplicationPool.CurrentIdentityType = [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser;
$webApp.ApplicationPool.Username = "mossdemo\mossadmin";
$webApp.ApplicationPool.Password = "password";
$title="Test Intranet" $description="Test Intranet"
$ownername="MOSS Administrator"
$webApp.Sites.Add("/", $title,$description,$locale,$sptemplate,$ownerlogin,$ownername,$owneremail)

All that’s needed is the port number to be passed to the code from the command line. If you’ve installed PowerShell then command prompt to the folder where this scipt file is and type in:
powershell .\<script file name>.ps1 8080

to create a web application on port 8080

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: