Databases Reference
In-Depth Information
If you don't have the sqlps module available the cmdlets will return nothing. You can make the mod-
ule available for use by importing it as shown below:
Import-Module sqlps
Aliases enable cmdlets to have different names, behavior embraced by the PowerShell team. As men-
tioned earlier, for example, DIR is available in PowerShell. It isn't in fact the DIR command you'll
i nd in the cmd.exe but rather a PowerShell Cmdlet called Get-ChildItem that has been aliased
to DIR for backward compatibility. Interestingly Get-ChildItem is also aliased to LS , which is the
equivalent command on UNIX platforms.
Variables
After you have written cmdlet statements in PowerShell, you need to be able to store data so that
it can be retrieved and manipulated further through your scripts. PowerShell provides variables to
store data within PowerShell. Variables always start with a $ symbol, followed by the name you
choose. For example, to store the top 10 processes by CPU usage you can use the following:
$TopTenProcessesByCPU = Get-Process | Sort-Object cpu -Descending | Select-Object -
First 10
Now that the value is stored in a variable, it is available for retrieval and further use through your
script.
You can discover all the variables that are available using the Get-Variable cmdlet. Table 14-2
shows some of the more important variables that were returned after I ran this on my machine.
TABLE 14-2: Common PowerShell Variables
VARIABLE NAME
DESCRIPTION
$_
Current item in the pipeline
$args
Array of arguments
$Error
Array of errors
$FALSE
Boolean False
$HOME
Folder containing the current user's profi le
$Host
This is a reference to the host of this runspace.
$null
References to the null variable always return the null value. Assignments have
no ef ect.
$PID
Current process ID
$PROFILE
Path to the active Profi le
Search WWH ::




Custom Search