Programming4us
         
 
 
Sharepoint

Working with the SharePoint 2010 Management Shell (part 2) - Understanding cmdlets

12/13/2010 2:42:23 PM

1. Understanding cmdlets

Window PowerShell cmdlets are utilities that are built on top of application interfaces, and in the case of SharePoint 2010, the SharePoint Object Module, and SharePoint Web Services, that allow administrators to complete a number of tasks.

In general, cmdlets use a verb-noun pair. The noun specifies the object you want information about or that you want to manipulate, and the verb states what you want to do with that object. The verbs and nouns are always separated by a hyphen with no spaces, and SharePoint cmdlet verbs have a prefix of SP. For example, if you want to get (the verb) information about all the content databases (noun) in your farm, you would use the following SharePoint cmdlet, which would give you the output shown.

PS C:\Users\Peter> Get-SPContentDatabase

Id               : a1d5c96c-a41a-43b3-bc5d-3f8a93b26046
Name : WSS_Content_a2fde53006e04bf5aae434ffd3c8a19c
WebApplication : SPWebApplication Name=SharePoint - 80
Server : SQL
CurrentSiteCount : 1
Id : 363b11a3-6947-42f6-9df4-665eeff59c83
Name : SPF_TeamsDB
WebApplication : SPWebApplication Name=SPF_Teams
Server : SQL
CurrentSiteCount : 1

Windows PowerShell also provides a few cmdlets that help you to work with the other cmdlets. Two examples of these are Get-Command, which can be shorted to gcm, and Get-Help, which can be shorted to help. (Shortened names of cmdlets are called aliases.) Get-Command allows you to find cmdlets, and then Get-Help can provide you with basic information about a cmdlet after it is retrieved. In the following example, the Get-Command finds all the cmdlets associated with SharePoint.

PS C:\Users\Peter>Get-Command -PSSnapin "Microsoft.SharePoint.PowerShell" |
>>sort noun, verb |Format-Wide -Column 3
>><ENTER>


Note:

When you type a one-line Windows PowerShell script, or you have not provided all the required parameters, Windows PowerShell either prompts you for the parameter or starts a new line with >> so that you can enter more commands. When you have finished typing, press Enter for Windows PowerShell to execute the code. Because of page size restrictions, many of the commands in this article are shown on multiple lines when they could be typed on one line, so always remember to press Enter only to execute the scripts.


The set of commands shown previously takes the output from the Get-Command cmdlet and pipes it to the sort cmdlet. The sort cmdlet sorts the data in noun-then-verb order so that all SharePoint cmdlets that manipulate the same object are listed together. The cmdlets that manipulate the same object are then sorted in verb order. To reduce the amount of scrolling necessary in the SharePoint 2010 Management Shell, the sorted data is piped to the format-wide cmdlet. Such a combination of Windows PowerShell cmdlets is quite common. The output from the command set would look similar to the following sample.

Start-SPAdminJob           Get-SPAlternateURL         New-SPAlternateURL
Remove-SPAlternateURL Set-SPAlternateURL Install-SPApplicationC...
Start-SPAssignment Stop-SPAssignment Get-SPAuthenticationPr...
New-SPAuthenticationPro... Get-SPBackupHistory Move-SPBlobStorageLoca...
Get-SPBrowserCustomerEx... Set-SPBrowserCustomerEx... Copy-SPBusinessDataCat...
.....(not all output shown)
Set-SPWebApplicationHtt... Get-SPWebPartPack Install-SPWebPartPack
Uninstall-SPWebPartPack Get-SPWebTemplate Install-SPWebTemplate
Set-SPWebTemplate Uninstall-SPWebTemplate Get-SPWorkflowConfig
Set-SPWorkflowConfig



Note:

There is another cmdlet similar to the Get-Command that helps you work with cmdlets and that you might find useful—especially if you create your own commands or scripts. It is the Measure-Command cmdlet. This command allows you to measure the time it takes to run cmdlets or scripts. You may also find the Trace-Command cmdlet useful for debugging short script blocks.


Other -----------------
- SharePoint 2010 : Edit the Contents of a Page
- SharePoint 2010 : Change the Page Layout of a Publishing Page
- SharePoint 2010 : Authoring Pages - Edit the Properties of a Page
- SharePoint 2010 : Authoring Pages - Create a New Page (part 2)
- SharePoint 2010 : Authoring Pages - Create a New Page (part 1)
- SharePoint 2010 : Managing Systems Remotely with WinRM
- SharePoint 2010 : Installing Windows PowerShell
- SharePoint 2010 : Using Windows PowerShell: The Basics
- SharePoint 2010 : Modify a View
- SharePoint 2010 : Create Mobile Views
- Uninstalling SharePoint 2010
- Configuring a SharePoint 2010 Installation (part 1) - Renaming the Central Administration Database
- Configuring a SharePoint 2010 Installation (part 1) - Running the Farm Configuration Wizard
- SharePoint 2010 : Enable or Disable Inline Editing in a View
- Performing SharePoint 2010 Installations (part 5)
- Performing SharePoint 2010 Installations (part 4)
- Performing SharePoint 2010 Installations (part 3)
- Performing SharePoint 2010 Installations (part 2)
- Performing SharePoint 2010 Installations (part 1) - SharePoint 2010 Standalone Installation
- SharePoint 2010 : Specify the Item Limit for a View
 
 
Most View
- Windows Server 2008 : Using PowerShell to Manage Active Directory (part 1) - Using the Active Directory Module in Windows Server 2008 R2, Creating and Manipulating Objects in Windows Server 2008
- Monitoring SQL Server 2005 Performance : Monitoring and Recording Performance
- SharePoint 2010 : Site Administration - Managing the Term Store
- Sharepoint 2010 : Backup and Restore (part 1) - Recycle Bin settings in Central Administration
- Exploring Group Policy in Windows 7
- Windows 7 : Protecting Yourself Against Email Viruses
- jQuery 1.3 : The Form plugin
- SharePoint Server 2010 Business Intelligence Platform (part 5) - PowerPivot
- SOA with .NET and Windows Azure : Service Implementation with WCF (part 2)
- SharePoint 2010 : Making Enterprise Content Management Work - Document Management (part 2) - Document Sets
Top 10
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 3) - Configuring Recipient Filtering
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 2)
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 1)
- Implementing Edge Services for an Exchange Server 2007 Environment : Installing and Configuring the Edge Transport Server Components
- What's New in SharePoint 2013 (part 7) - BCS
- What's New in SharePoint 2013 (part 6) - SEARCH
- What's New in SharePoint 2013 (part 6) - WEB CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 5) - ENTERPRISE CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 4) - WORKFLOWS
- What's New in SharePoint 2013 (part 3) - REMOTE EVENTS