A SharePoint cmdlet (pronounced “command-let”) is a single-function, light weight command in PowerShell. Cmdlets follow a verb-noun naming convention. To see these in action, open up your SharePoint 2010 Management Shell and type the following:


Figure 1.1

The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify and can be formatted in a number of ways. Take notice that is returns an object. An object is a container of functions that can act autonomous of other objects. We discuss objects in more detail shortly. SharePoint 2010 offers over 500 cmdlets that perform a number of functions or return objects. With such a large number, just in SharePoint, PowerShell offers a cmdlet to help you with cmdlets. To see this in action, we will examine the cmdlet that creates a new configuration database for SharePoint: New-SPConfigurationDatabase. In the shell window, type the following:

Get-Help New-SPConfigurationDatabase

Figure 1.2
 The Get-Help comdlet returns informaiton about the cmdlet passed in.  It returns the name, synopsis, sytax, description, related cmdlets, and a remarks section.  You can use this information to help peice together how to build the appropriate syntax.  Examine the syntax section.

New-SPConfigurationDatabase [-DatabaseName] <String> [-DatabaseServer] <String> [[-DirectoryDomain] <String> [[-DirectoryOranizationUnit] <String>] [[-AdministrationContentDatabaseName] <String>] [[-DatabaseCredentials] <PSCredential>] [-FarmCredentials] <PSCredential> [-Passphrase] <SecureString> [-AssignmentCollection <SPAssignmentCollection>] [<CommonParameters>]

You will see that this cmdlets requires pieces of information in order to complete the task of creating the configuration database. These pieces are call parameters. The first parameter that is required is DatabaseName. DatabaseName takes input that is in a string format.

Let’s take a look at an example, so that you can see the use of parameters in action. For this example, we look at the cmdlet just introduced.

New-SPConfigurationDatabase –DatabaseName “SharePoint2010_Config” –DatabaseServer “MySQL1” –AdministrationContentDatabaseName “SharePoint2010_Admin_Content” –Passphrase (ConvertTo-SecureString “pass@word1” –AsPlaintext –Force) –FarmCredentials (Get-Credential)

New-SPConfigurationDatabase has five parameters are associated with it. The parameters are preceded with variables denoted with a hyphen.

  • Database – “SharePoint2010_Config”
  • DatabaseServer – “MySQL1”
  • AdministrationContentDatabaseName – “SharePoint2010_Admin_Content”
  • Passphrase – “pass@word”
  • FarmCredentials – (Get-Credential)

In the above example, the parameters are all surrounded with quotes with the exception of FarmCredentials which calls a function that will prompt the user for his username and password. This allows you to script repetitive tasks without the need for exposing confidential information.

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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s