Intro to PowerShell 1 – The PowerShell CLI
Start with the basics
Author’s Note:
This is the first installment of a three-part Introduction to PowerShell tutorial. This is guide is not intended to be an exhaustive treatise on PowerShell. If that is what you’re after, search PowerShell on Amazon. This is intended to be used simply as an introduction by those who are new to Microsoft’s scripting and automation language of choice.
I’m a big fan of interactivity. If you’d like to play along with and become familiar with the various parts of PowerShell environment as we cover them I strongly encourage you to do this. You may already have PowerShell installed on the machine you’re using. If you don’t, you can get it from here.
Introduction
Unless you’ve been living under a rock, or are just starting out with Server Administration, then chances are fairly good that you’ve at least heard of PowerShell. Introduced in 2006 and currently on version 4*, Windows PowerShell is a task automation and configuration management framework from Microsoft built on the .NET Framework.
The complete PowerShell environment consists of:
- A CLI and associated scripting language,
- Cmdlets (pronounced command-lets),
- The ISE.
First cab off the rank is the a quick and dirty introduction to the PowerShell CLI.
The PowerShell CLI
First a little background. If you open your start menu and type cmd in the search and press enter you’ll be presented with the classic windows command line interface or CLI. This CLI, although quite powerful within certain narrow boundaries, is extremely limited when it comes to providing a scripted management interface. You can of course run batch files and accomplish a level of automation using this command line, but it is still quite limited.
Nearly a decade before PowerShell was released it became apparent to Microsoft that Windows needed a way to easily provide access to certain core functionality in both the consumer and server version of Windows. To cut a long (and really quite boring) story short, after several abortive attempts the PowerShell CLI and scripting language was born.
There are various methods to access the PowerShell CLI but the easiest way is to simply click on the start menu (or press the start key in windows 8) and type Windows Powershell then press enter. By default this will then open up the latest version of the PowerShell CLI.
The first thing you will probably notice is that the newly opened window has a blue background but otherwise looks similar to the cmd prompt we launched earlier. While the PowerShell CLI and cmd prompt look similiar, one is considerably more powerful than the other. For instance I can use the dir command in both the CLI and cmd. Runnig the dir command and then saving the output to a file in the CLI is as simple as typing a one line command. To do the equivalent of this with cmd I would need to write a multiple line batch file.
Activity: Getting help in the Powershell CLI
The simplest way to start becoming familiar with the PowerShell CLI and how we run commands is to actually run some commands and view the results. There are a number of places we could start, but my personal favourite is to start by asking the CLI for help.
The command for this is Get-Help.
One of the reasons I specifically like to start with Get-Help is that the first time you run it it demonstrates that the PowerShell CLI is an interactive shell and not just a command interpreter.
When you first run the Get-Help command, you will be presented with the option seen in the figure below:
Typing Y or simply hitting enter at this point will cause the Get-Help command to initiate a download of the latest help files.
Once the update of the help files has finished, quite a lot of text will be outputted into the CLI. If you would like more of an idea on how to use the Get-Help command then you can read this text. Otherwise, congratulations are in order. Not only do you now have a basic familiarity with the PowerShell CLI, you have also run you’re first CMDlet.
Outcomes
Today we covered:
- The background to PowerShell
- Accessing the PowerShell CLI.
- Differences between the PowerShell CLI and the Command Prompt
- Running a Simple Command in the Powershell CLI
- The Interactivity of Commands in the PowerShell CLI
*PowerShell v5 was released by Microsoft as an initial public preview in April 2014. It is expected that Microsoft will release the new version alongside Windows 10 and its equivalent Server version.
- Intro to PowerShell 3 – The PowerShell ISE - December 11, 2014
- Intro to PowerShell 2 – Cmdlets - December 11, 2014
- Intro to PowerShell 1 – The PowerShell CLI - December 11, 2014
- BigPanda cuts the chatter - November 20, 2014
- Stratusphere FIT and UX solutions hit 5.7 - November 10, 2014
- Review: ioSafe 1513+ - November 6, 2014
- Quaddra provides Storage Insight - November 5, 2014
- Unsatisfactory Responses - July 15, 2014
- Disabling the Windows Update Framework - April 8, 2014
- Behind The Servers S1E1 - March 27, 2014