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 -----------------
- Working with the SharePoint 2010 Management Shell (part 1)
- 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
 
 
Most View
- Windows 7 : Deleting Unnecessary Files
- Windows 7 : Understanding User Account Control (part 1) - Elevating Privileges
- Windows Azure: Building a Secure Backup System (part 6) - Uploading Efficiently Using Blocks
- SQL Server 2008 Scheduling and Notification : Configuring the SQL Server Agent
- Business Apps for Android & Windows Phone 7 : Handyscan, Outdoor Navigation, Pageonce Money& Bills, Glympse, Cool Tools
- Using Exchange 2007 as a Public Folder Replica
- SharePoint 2010 : Use the Picture Editing Control in a Page
- Windows Phone 7 Game Development : Lighting (part 2) - How XNA Calculates Light Reflections
- Windows 7 : Getting to the Command Line (part 2) - Running CMD
- Windows7: General Solutions to Network Problems (part 2) - Updating the Router Firmware
Top 10
- jQuery 1.3 : Improving a basic form (part 1) - Progressively enhanced form styling
- Programming Windows Azure : Table Operations - Querying Data
- Windows 7: Working with Device Security Policies
- SharePoint 2010 : Excel Services - Using the JavaScript Object Model
- Windows Firewall with Advanced Security in Windows Server 2008 (part 1)
- SQL Server 2008 : Performance Data Collection (part 2)
- SharePoint 2010 : Search for People (in SharePoint Server)
- Securing Windows 7 : Thwarting Snoops and Crackers (part 2) - Locking Your Computer Manually, Automatically
- Scripting Windows 7 with WSH : Programming Objects
- SharePoint 2010 : Approve or Reject a File or List Item