Databases Reference
In-Depth Information
As you can see in the example below, the machine is set up so that downloaded scripts must be
signed to run, but scripts created on the computer don't have to be signed to run.
PS > Get-ExecutionPolicy
RemoteSigned
The Basics — Cmdlets, Variables, Advanced Functions,
and Modules
PowerShell is created upon a few core building blocks. A thorough understanding of these constitu-
ent parts will make understanding the environment a lot easier, so the following sections describe
these core components.
Cmdlets
Cmdlets follow a naming convention to assist with identii cation. This convention is [ Name ]-[ Verb ],
such as Get-Process , Get-Help , and Remove-Item .
Cmdlets are .NET classes that provide a single piece of functionality and are either provided with
the PowerShell environment or provided by .NET developers and installed into the environment.
They can take PowerShell objects as input and provide PowerShell objects as output. This ability
to take and return PowerShell objects enabled the framework creators to offer what's known as a
pipeline. Using pipelines, you can construct single lines of PowerShell that contain multiple cmdlets,
each passing the output as input to the next, with cmdlets participating in the pipeline separated
by the bar operator (|). Very powerful functionality can be composed in a single line of PowerShell
using this functionality. The following example uses the Get-Process cmdlet to list all the run-
ning processes on the computer, and then the output of the Get-Process cmdlet is connected to the
Export-Csv cmdlet, which exports the list of processes to a CSV i le:
Get-Process | Export-Csv .\processes.csv -NoTypeInformation
Discovering functionality is important in the command line because unlike in a GUI where you
can visually scan through the menu items, you need to instead use discoverability tools that are
provided with PowerShell. The i rst cmdlet to be aware of is Get-Help . Get-Help takes one param-
eter CmdletName or TopicName . You can also provide a few properties: -examples to display the
examples; -detailed to get further information; and -full for all the technical information. The
following example uses Get-Help to retrieve all the information about the Get-Process cmdlet:
Get-Help Get-Process -full
In order to “ Get-Help ” you need to know the cmdlets that are available, and PowerShell provides
the Get-Command cmdlet for just that purpose. If you are trying to i nd all the cmdlets available
within a module, you can specify the module name to i lter the results to only the commands that
exist within the module. The module name for SQL Server 2012 is SQLPS, so you can i nd all the
cmdlets provided with SQL Server 2012 with the following:
Get-Command -Module sqlps
 
Search WWH ::




Custom Search