Pages

Wednesday, November 3, 2010

PowerShell OverView and Examples with SharePoint 2010

OverView:
PowerShell is a command line scripting tool which introduces the concept of a cmdlet, those commands that are derived from the System.Management.Automation .Cmdlet class and are created using the .NET Framework.
For Example,
(Get-SPWeb -Identity http://localhost).Title
or
$RootSite=Get-SPWeb -Identity http://localhost
$ RootSite.Title
Examples:
  • Setting Properties on SharePoint Objects
           $ RootSite =SP-GetSPWeb -Identity http://siteurl
           $ RootSite.Title="My First Site"
           $ RootSite.Update()
  • Connecting to SharePoint Remotely
          Powershell is very powerful; with the powershell we can connect with remote machine and  open a PowerShell session on a client machine.
         To enable remoting on the server, enter the following command:
         Command: Enable-PSRemoting
         To connect to any machine by entering the following command:
         Command: Enter-PSSession "Server Name" -Credential (Get-Credential)
         Once a remote connection has been established, the SharePoint snap-in can be added with the  command:
         Command: Add-PSSnapin Microsoft.SharePoint.PowerShell
  • Working with Timer Jobs
             Get-SPTimerJob | Select -Expand HistoryEntries | Where {$_.Status -ne "Succeeded"} |
             group JobDefinitionTitle
Like these , We can do so many operations by running different commands of PowerShell like “Create/Delete  Site Collections and Site”, ”Properties on Sharepoint Objects”,”Lists and Libraries” etc.
Disha Shah

No comments:

Post a Comment