Intro to PowerShell 3 – The PowerShell ISE Dec11

Intro to PowerShell 3 – The PowerShell ISE

In the first two parts of this series (part 1; part 2) we covered the PowerShell CLI and the associated scripting language, and we also covered Cmdlets and discovered how they’re the fundamental building blocks of the PowerShell world. In this part we will be discussing the PowerShell ISE and what it can do for you. Introducing the .ps1 file format. In Part 2 of this series we ran 3 commands in the CLI to validate a directory path, create a non-existent directory and then pipe the output of the DIR command to a text file. We did all of this from the CLI because that’s how you manually enter commands for PowerShell to run. This is a bit clunky though. If we had to open the CLI every time we wanted to run commands in PowerShell its usefulness and indeed its real world applications would be limited at best. Much like the CMD prompt had batch scripts, PowerShell has its own scripting file format that allows us to write scripts and run them all at once or even as part of an automated procedure. Enter the .ps1 file. A .ps1 file is essentially the next step in the evolution of the .bat file. Like batch files, a .ps1 file is a plain text file that the PowerShell interpreter steps through line by line, running the individual commands sequentially and combining the output as necessary. For example, if we were to combine the three commands from the exercise in Part 2 into a .ps1 file (for the sake of this example we’ll call it ITPS_B3_Example1.ps1) we would start off with something that looks like this: Test-Path C:\Utils New-Item C:\Utils -ItemType directory dir | Out-File C:\Utils\dir.txt Running a script from windows explorer is as easy...

Intro to PowerShell 2 – Cmdlets Dec11

Intro to PowerShell 2 – Cmdlets

In part 1 of this series we were introduced to the PowerShell CLI and ran the Get-Help command. In this part we will introduce you to Cmdlets. Introducing Cmdlets Cmdlets (pronounced command-lets) are specialised commands used in the PowerShell environment to call specific functions. To put this another way, Cmdlets are simple ways of calling and executing the pre-built commands in PowerShell. PowerShell Cmdlets are easily identifiable because they use binomial nomenclature – ie there are always 2 parts to the name and both parts are separated by a hyphen. For example: The Get-Help command that we used in Part 1 is actually a Cmdlet. In part 1 of this series I mentioned that we could pipe the output of the legacy dos command DIR to a file with a single line entered into the PowerShell CLI. To do this we would enter the following text in the PowerShell CLI: dir | Out-File C:\Utils\dir.txt In plain English this says “Take the output of the dir command and give it to the Cmdlet Out-File to be written to the file dir.txt in the C:\Utils\ path. Pretty powerful stuff for a command that is only 31 characters long. You might have noticed that there is a character in that command that you might not be familiar with. It’s the | character and on most US style keyboards it’s located on the same key as the \ key. The | character is what we refer to as the pipe operator. It tells PowerShell to take the output of what comes before and hand it off to what comes next. For more information on the | operator and the fun you can have with it, take a look at the activity below. Cmdlets then are the building blocks...

Intro to PowerShell 1 – The PowerShell CLI Dec11

Intro to PowerShell 1 – The PowerShell CLI

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...