20
Dec
09

Working with PowerShell in SharePoint 2010

It’s is really good to see the way the PowerShell interacts with the SharePoint 2010. I can say that this PowerShell scripting is really an extended form of the STSADM utility with additional programmatically features which can be achieved through batch files.
In this post I am going to show you how PowerShell works… and some tips and tricks for the PowerShell module on the SharePoint 2010
Let’s us create a new Web under the PowerShell console for the SharePoint 2010. To create a new Web under the existing Site Collection, PowerShell scripting will use the following command
“New-SPWeb”
The following are the input parameters for the respective command.
SYNTAX
New-SPWeb
[-Url] <String>
[-Language <UInt32>]
[-Template <SPWebTemplatePipeBind>]
[-Name <String>]
[-Description <String>]
[-AddToQuickLaunch]
[-UniquePermissions]
[-AddToTopNav]
[-UseParentTopNav]
[-AssignmentCollection <SPAssignmentCollection>]
[-Verbose]
[-Debug]
[-ErrorAction <ActionPreference>]
[-WarningAction <ActionPreference>]
[-ErrorVariable <String>]
[-WarningVariable <String>]
[-OutVariable <String>]
[-OutBuffer <Int32>]
[-WhatIf]
[-Confirm]

PowerShell provides us a set of commands which draws out the SharePoint Out-Off-Box functionalities and also it extends the SharePoint Object model.

Write-Host “Defining variables for creating a new Web under the different Site Collection”
# define variables for script
$SiteTitle = “Lab 1 – Getting Started”
$SiteUrl = “http://sharepoint2010v/Lab01/”
$SiteTemplate = “STS#0″
Write-Host “Creating a new SharePoint Web under the URL – “ $SiteUrl
PS C:\> New-SPWeb -Url $SiteUrl -Template $SiteTemplate -Name $SiteTitle
Write-Host “New SharePoint Web has been successfully created.”

Pack the above code snippet in a notepad and save it as CreateNewSite.ps1

Powershell -Command “& {.\CreatenewSite.ps1}” -NoExit
pause

Again pack the above two lines of code as a batch file and save it as “ExecuteNewSiteCreation.bat”
Now, run the above created “ExecuteNewSiteCreation.bat” file. PowerShell creates a new Web under the specified Site Collection…
Note: you should modify the “$SiteUrl” variable in order to execute the above scenarios.

Happy programming… will see more updates on the Powershell developement on SharePoint 2010…

Advertisement

0 Responses to “Working with PowerShell in SharePoint 2010”



  1. Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s


Calendar

December 2009
M T W T F S S
« Nov   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1 other follower


Follow

Get every new post delivered to your Inbox.