Basic PowerShell

PowerShell, like any language, consists of commands, variables, functions, flow control methods, and other features necessary to enable work to be done. Because it is an interpreted language, the scripts don't have to be compiled into an executable form to be run.

Language Features

A cmdlet (pronounced “command-let”) is a command-line utility built into PowerShell to provide some functionality. These cmdlets use a verb-noun naming convention, so it's easy to understand what they're doing. Microsoft has provided approximately 236 built-in cmdlets with the default installation of PowerShell (2.0), and additional cmdlets are installed depending on various server products that may be running. PowerShell 3.0 will be available in late 2012, but because it wasn't ready for release when SQL Server 2012 was shipped, the focus of this chapter is on PowerShell 2.0. (Version 3.0 expands the PowerShell language and introduces a more powerful integrated scripting environment, similar to Visual Studio.) All future development should take place inside the PowerShell 3.0 ISE if you have access to it. Its many built-in features are far superior to the simple console window.

Cmdlets are frequently aliased. In other words, a different command can be entered to run the cmdlet, rather than using its own name. For example, when browsing a directory, the PowerShell cmdlet to view the contents of the current directory is Get-ChildItem. Users of the DOS operating system (or cmd.exe on current ...

Get Microsoft SQL Server 2012 Bible now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.