Sample PowerShell Script for creating a web application in SharePoint 2010
# add SharePoint Powershell snapin
add-PSSnapin Microsoft.Sharepoint.powershell
#define variables
$WebAppName=”SharePoint – 120″
$WebAppPort=120
$WebAppUrl=”http://servername:port/”
$WebAppPool=”SharePoint – 120″
$WebAppPoolAccount=”domain\password”
$WebAppDatabaseServer=”servername\SHAREPOINT”
$WebAppDatabaseName=”WSS_Content_120″
new-SPWebApplication -name $WebAppName -url $WebAppUrl -ApplicationPool $WebAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppPoolAccount) -DatabaseServer $WebAppDatabaseServer -DatabaseName $WebAppDatabaseName
write-host “New Web Application successfully created”
write-host “—————————————-”
write-host “Application name ” $webAppName -foregroundcolor Green
Sample PowerShell Script for deleting a web application in SharePoint 2010
$WebAppUrl=”http:/servername:port”
write-host “Begin Deleting Web Application at ” $WebAppUrl
write-host
Remove-SPWebApplication -Identity $WebAppUrl
write-host “New wEb Application successfully deleted”
Sample PowerShell Script for Creating Site Collection in SharePoint 2010
if($args)
{
$sitename=$args[0]
$siteurl=”http://servername:port/sites/” + $SiteName
write-host “Begin Creating Site Collection at ” $SiteUrl
write-host
$NewSite = New-SPSite -Url $SiteUrl -OwnerAlias Administrator -Template STS#1 -Name $SiteName
$RootWeb=$NewSite.RootWeb
$RootWeb.Title=”Scripted Site -” + $SiteName
$RootWeb.Update()
write-host “New Scripted Site successfull created”
write-host “Title: ” $RootWeb.Title -foregroundcolor Green
}
else{
write-host “Error : You must supply parameter for site name” -foregroundcolor Red
}
For Deleting the SiteCollection
if($args)
{
$sitename=$args[0]
$siteurl=”http://servername:port/sites/” + $SiteName
write-host “Begin Deleting Site Collection at ” $SiteUrl
write-host
Remove-SPSite -Identity $siteurl
write-host “New Site successfully deleted”
}
else
{
write-host “Error : You must supply parameter for site name” -foregroundcolor Red
}
Save the script files with the extension .ps1
To run them
./filename.ps1
Few other important PowerShell command (Get-Help, Get-Location, Set-Location)
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

Very good article! We are linking to this great post on our site.
Keep up the good writing.
LikeLike
Hi, I would like to subscribe for this webpage to obtain most up-to-date updates, so where can i do it
please help out.
LikeLike
Hello would you mind letting me know which hosting company
you’re utilizing? I’ve loaded your blog in 3 completely different
internet browsers and I must say this blog loads a
lot quicker then most. Can you recommend a good internet hosting provider at a honest price?
Thank you, I appreciate it!
LikeLike
It’s amazing to visit this web page and reading the
views of all colleagues regarding this article,
while I am also zealous of getting familiarity.
LikeLike