PowerShell/Console

This lesson introduces the PowerShell console by looking at cmdlets, the pipeline, and redirection.

Objectives and Skills
After completing this lesson, you will be able to:
 * Customize the PowerShell console interface.
 * Use the PowerShell console interface to run cmdlets.
 * Use the PowerShell pipeline to select, sort, and filter content.
 * Use redirection to save PowerShell output as a file.

Readings

 * 1)  Command-line interface
 * 2)  Pipeline (Unix)
 * 3)  Redirection (computing)
 * 4)  Comment (computer programming)
 * 5) BonusBits: Mastering PowerShell Chapter 1 - The PowerShell Console

Multimedia

 * 1) Microsoft Virtual Academy: Getting Started with PowerShell 3.0
 * 2) YouTube: Customizing the Shell

Comments
Comments are added to a PowerShell script using the hashtag or number sign character (#).

Block Comments
Block comments are added to a PowerShell script using <# and #>.

Get-Command
The Get-Command cmdlet lists all PowerShell commands.

Get-Date
The Get-Date cmdlet returns the current date and time.

Get-Process
The Get-Process cmdlet lists all running processes.

Get-Service
The Get-Service cmdlet lists all installed services.

Select-Object
The Select-Object cmdlet selects objects or object properties.

Sort-Object
The Sort-Object cmdlet sorts objects based on property values.

Where-Object
The Where-Object cmdlet selects objects based on their property values.

Redirection
The > character is used to redirect pipeline output to a file. The >> combination appends pipeline output to the file.

Activities

 * 1) Experiment with customizing the PowerShell console properties, including font, screen buffer size, and colors.
 * 2) Review Microsoft TechNet: Using the Select-Object Cmdlet. Use PowerShell, the Get-Host and Select-Object cmdlets, and the pipeline to select the name of the host environment. Then use PowerShell ISE to test the same command.
 * 3) Use the Get-Host and Select-Object cmdlets and the pipeline to select the PowerShell version number.
 * 4) Review Microsoft TechNet: Using the Get-Command Cmdlet. Run the Get-Command cmdlet and redirect the output to a file. Open the file to view the results.
 * 5) Review Microsoft TechNet: Using the Get-Process Cmdlet and Microsoft TechNet: Using the Sort-Object Cmdlet. Use a combination of Get-Process and Sort-Object to display a list of the running processes sorted by CPU usage in descending order (greatest to least).
 * 6) Review Microsoft TechNet: Using the Get-Service Cmdlet and Microsoft TechNet: Using the Where-Object Cmdlet. Use the correct combination of Get-Service, Select-Object, Sort-Object, and Where-Object to display a list of running services sorted in alphabetical order by display name, showing the display name only.

Lesson Summary

 * A command-line interface (CLI), also known as command-line user interface, console user interface, and character user interface (CUI), is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines).
 * The interface is usually implemented with a command line shell, which is a program that accepts commands as text input and converts commands to appropriate operating system functions.
 * Programs with command-line interfaces are generally easier to automate via scripting.
 * A command prompt (or just prompt) is a sequence of (one or more) characters used in a command-line interface to indicate readiness to accept commands.
 * A CLI can generally be considered as consisting of syntax and semantics.
 * The syntax is the grammar that all commands must follow. These rules also dictate how a user navigates through the system of commands.
 * The semantics define what sort of operations are possible, on what sort of data these operations can be performed, and how the grammar represents these operations and data—the symbolic meaning in the syntax.
 * A command-line argument or parameter is an item of information provided to a program when it is started.
 * A command-line option or simply option (also known as a flag or switch) modifies the operation of a command.
 * Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command.
 * A pipeline is a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one.
 * To use the pipeline, one writes the commands in sequence, separated by the ASCII vertical bar character "|" (which, for this reason, is often called "pipe character").
 * By default, the standard error streams of the processes in a pipeline are not passed on through the pipe; instead, they are merged and directed to the console.
 * Redirection is a function common to most command-line interpreters that can redirect standard streams to user-specified locations.
 * Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows, using < to redirect input, and > to redirect output.
 * To append output to the end of the file, rather than overwriting it, use the >> operator.
 * A comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program.
 * Comments are added to a PowerShell script using the hashtag or number sign character (#).
 * Block comments are added to a PowerShell script using <# and #>.
 * The name of the PowerShell console executable program is powershell.exe.
 * PowerShell commands are cancelled by pressing +.
 * The  key is used to complete PowerShell input automatically.
 * The PowerShell console font, window size, buffer size, and other options are configured using the console Properties dialog box.
 * PowerShell output may be displayed one page at a time by piping output through the More function, as in command | more.
 * The Get-Command cmdlet lists all PowerShell commands.
 * The Get-Date cmdlet returns the current date and time.
 * The Get-Process cmdlet lists all running processes.
 * The Get-Service cmdlet lists all installed services.
 * The Select-Object cmdlet selects objects or object properties.
 * The Sort-Object cmdlet sorts objects based on property values.
 * The Where-Object cmdlet selects objects based on their property values.

Key Terms

 * argument
 * One of the pieces of data provided as input in a parameter to a subroutine.


 * buffer
 * A region of a physical memory storage used to temporarily store data while it is being moved from one place to another.


 * default
 * A setting or a value automatically assigned to a software application, computer program or device, outside of user intervention.


 * delimiter
 * A sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams.


 * environment variable
 * A dynamic named value that can affect the way running processes will behave on a computer.


 * escape character
 * A character which invokes an alternative interpretation on subsequent characters in a character sequence.


 * option
 * Text that modifies the operation of a command, with the effect determined by the command's program.


 * parameter
 * A special kind of variable, used in a subroutine to refer to one of the pieces of data, or arguments, provided as input to a subroutine.


 * pseudocode
 * An informal high-level description of the operating principle of a computer program or other algorithm.


 * stdin (standard input)
 * The stream of data (often text) going into a program.


 * stdout (standard output)
 * The stream where a program writes its output data.


 * stderr (standard error)
 * Another output stream typically used by programs to output error messages or diagnostics.


 * stream
 * A sequence of data elements made available over time.

Assessments

 * Flashcards: Quizlet: Windows PowerShell - Console
 * Quiz: Quizlet: Windows PowerShell - Console