PowerShell is a huge topic to which
entire books have been dedicated, and highly experienced users teach
weeklong classes on PowerShell. Many of the SharePoint
PowerShell cmdlets can be used as one-liners or “standalone,” so a
comprehensive understanding of PowerShell is not necessarily required.
That said, understanding a few PowerShell concepts in conjunction with
the SharePoint cmdlets can greatly facilitate your work.
Listing the SharePoint Commands
The toughest part of using a
command-line interface, whether it’s PowerShell, the old Windows CMD
prompt, or a Linux bash shell, is determining which commands you can
use. You can sit a drunk koala bear in front of Central Administration
and it can click around long enough to figure out to do tasks like
create a site collection. If you sit that same koala down in front of a
PowerShell prompt you’ll get koala spittle on your keyboard but no new
site collections. The learning curve to PowerShell can be steep, and
discovering the right command is a big reason why.
Fortunately, PowerShell provides the Get-Command cmdlet to retrieve a list of available commands. Used in isolation, the Get-Command cmdlet will return all commands that are known to the host. Get-Command,
like many commands, accepts optional parameters. Because we are
interested in only the SharePoint 2013 commands, we can limit the
commands displayed to just the SharePoint 2013 commands by using the
optional -Module parameter. To list only SharePoint commands, execute the following command:
Get-Command -Module Microsoft.SharePoint.PowerShell
Figure 1 displays the output of the Get-Command cmdlet using the –Module parameter.
We mentioned earlier that all PowerShell cmdlets
consist of a verb and a noun. All the nouns in the SharePoint
PowerShell cmdlets start with “SP.” The Get-Command
cmdlet accepts wildcards, which you can use to get a list of all the
SharePoint PowerShell cmdlets in an easier-to-remember method:
Get-Command -noun sp*
At last count, more than 750 PowerShell cmdlets
were included with SharePoint 2013, which is probably many more
commands than you want to list, unless you are printing them out for
some kind of tree-killing reference manual. As the preceding example
demonstrates, you can filter the list somewhat by using the optional -noun or -verb parameter for Get-Command. For example, if you were wondering what commands work with a web application, use the following command:
Get-Command –Module Microsoft.SharePoint.PowerShell –noun SPWebApp*
Because the SharePoint module is the only module
with cmdlets using the SPWebApplication noun, you would get the same
results if you omitted the –module
parameter. However, it’s a good idea to leave it if you’re searching by
verb, as the SharePoint cmdlets use the same verbs as the
non-SharePoint cmdlets. If you need to know which command to use for
backups, use the following command:
Get-Command –Module Microsoft.SharePoint.PowerShell –verb Backup
Figure 2 shows how you can control the output of Get-Command with the –noun and –verb parameters.