Windows PowerShell Console
PowerShell Tutorial 1: Configuring the PowerShell Console
PowerShell is required for tutorials on this site. If PowerShell is not installed on the system, please do so before moving on. A page on this site has been provided to assist in installing PowerShell. It can be found at Categories -> PowerShell Downloads -> Download PowerShell 1.0.
This tutorial is an introduction to PowerShell, PowerShell concepts, and exercises in customizing the PowerShell Console.
PowerShell is a new… ok how many times have you read that already? PowerShell is a new command shell from Microsoft and yes it is a command prompt and scripting environment, it can even be both at the same time. But what does PowerShell really mean for a systems administrator? What are the benefits in learning PowerShell? If you manage resources with VBScript you already know the answers. Active Directory domains are becoming larger and more complex. For those administrators that are still chained to GUI tools and the Microsoft Management Console, PowerShell will set you free!!!
It has become a daunting task to manage resources in large domains, GUI just won't DUI anymore. For example, take the recent DST (Daylight Savings Time) change. Microsoft was slow to respond (in my opinion) but did supply hot fixes for XP and Windows 2003. Windows 2000 was a different story, system admins had to rely on a manual edit using tzedit.exe (unless you had a premier contract). Am I bringing back any nightmares? Here was my nightmare; the boss asked, "How do we know that the DST hot fixes and the manual tzedit actually worked?" Gulp! Thank god I was already working on the answer to that question. I found a KB Article posted on the Microsoft web site listing the new DST registry entries and their locations. So with VBScript I enumerated the registry settings, based on operating system version, and created a report. I found a 25% failure rate after applying hot fixes and tzedit. So, I wrote another script that would edit the registry settings with the proper configuration. Thankfully, all of my Server Systems (300+) sprung ahead to the proper DST settings. Ok, so now you are thinking "why are we talking about VBScript? This is a PowerShell tutorial!!!" My point is, I know a lot of IT workers that had to manually update the registry when the clocks didn't roll forward, message boards and forums were full of postings. What would you rather do, logon to each server and manually fix the problem or run a script to fix the issue for you? PowerShell would have been a great tool for this situation; I was just more familiar with VBScript at the time.
I've read and been asked the following, "VBScript is still a viable tool… so why should I learn PowerShell?" I have a couple of simple answers for that:
- PowerShell was designed for .NET objects; VBScript does not support a method for communicating or interacting with .NET. We will talk more about .NET in later tutorials.
- Learning PowerShell will further advance your career. Trust me, it will.
This Introduction was not based on what PowerShell is but what PowerShell, as a Shell and a Scripting Language, can do for you. The DST example is only the tip of the iceberg when is comes to the power of scripting languages. What PowerShell "is" you will discover as you continue learning. What's great about PowerShell, you will be able to use it right out of the gate to complete simple tasks. As your knowledge grows you will be able to take on more complex tasks.
PowerShell is object-based not text-based
This concept will take a little time grasp for dos/cmd.exe and batch script writers. Those using VBScript and other programming languages already understand the concept. The basic difference, traditional command prompt output is text-based while output in PowerShell is not. It looks like text but it is actually an object. Why is this powerful? Because the output of a PowerShell command (the object) can be piped into another command without additional programming. With traditional scripting, if you wanted to use the output of one command in another, additional programming would be required to manipulate the data in a format the second command could understand. What is an object? This should sound familiar to the Windows Administrators out there… "Everything in an Active Directory Domain is an object." Servers, Computers, Printers, Shares, Organizational Units, Security Groups, Group Policy Objects, Users, etc… With PowerShell we can interact with these objects to enumerate information (object-properties) and/or create, modify, or delete objects and/or object-properties (object-methods).
PowerShell Commands are customizable
PowerShell commands are referred to as Cmdlets. With the installation of PowerShell there are over a hundred cmdlets for you to get up close and personal with. The PowerShell team, in their infinite wisdom, created aliases to allow us to use the traditional commands we have become accustomed to (dir, cd, del, copy, etc…). Even the UNIX guys get a break with provided aliases (ls, man, etc…). PowerShell allows you to create your own aliases as well as creating your own cmdlets. Yep, unlike dos/cmd and reskit exe's, PowerShell provides a method to create your own PowerShell cmdlets.
PowerShell is a Command line interpreter and a scripting environment
In a nutshell you have the best of both worlds within PowerShell. DOS was a command line interpreter, enter command get output. Sure you could use batch files, but in reality a batch file just entered the commands for you. VBScript utilizes WSH (Windows Scripting Host); you can't enter VBScript code in a command prompt. With PowerShell not only can you enter commands, you can build script-blocks from the PowerShell command line. You will be doing this in later tutorials.
Windows PowerShell Console
Let's take a look at the Windows PowerShell Console. Go to Start -> Programs -> Windows PowerShell 1.0 -> Windows PowerShell
You can also launch PowerShell from a command prompt or in start -> run by simply typing powershell
You will notice the command prompt PS U:\>
PS signifies that you are running PowerShell, U: is the drive letter of my home directory. Yours may be different.
Exercise 1: Customize a shortcut to point to a home directory
As you have noticed my prompt points to U: Drive. I like to organize my scripts in one location where I can access them quickly. U: is a drive mapping to my home directory on a file server. I've chosen my file server as it is backed up nightly. In this exercise we configure the PowerShell Console to open in a directory called "MyScripts."
- Create the following directory – C:\MyScripts.
- Create a PowerShell shortcut on your desktop.
- Right-Click on the shortcut and choose Properties.
- Under the Shortcut tab locate the Start in: text box. Type in the path to the folder created in step 1. C:\MyScripts
- Click Ok.
- Launch PowerShell from the desktop shortcut.
PowerShell starts in the directory path we've chosen:
Feel free to choose the directory path of your choice. If your path has a space in it, don't forget to double-quote it. Example: "C:\Program Files\MyScripts." I will be working from the C:\MyScripts directory path throughout the tutorials.
Exercise 2: Customizing color and text-size
Remember the DOS prompt with the blue background and yellow text? Ok, I'm dating myself but at least I didn't say monochrome. I'm going to change the shortcut to those colors.
- Right-click on the shortcut and choose Properties.
- Choose the Colors tab.
- You will see four radio buttons; Screen text, Screen background, Pop-up text, and Pop-up background. The Screen buttons are self-explanatory; the Pop-up buttons are for colors used in the History Buffer.
- Set Screen text to yellow, Screen background to blue.
- Launch PowerShell from the desktop shortcut.
PowerShell runs in the colors we've chosen:
Next I'm going to make the text larger so I don't have to squint.
- Close the PowerShell Console by typing exit.
- Right-Click the PowerShell shortcut and choose Properties.
- From the Fonts tab, choose 12 x 16. Click OK.
- Launch PowerShell from the shortcut.
Do you see the following? I mean can you really see it now?
Take a few minutes and play around with all the options in the shortcut's properties. Customize the shell to your preference. If you want to go back to the default text-size it is 8 x 12. You can also get to properties by clicking on the PowerShell icon in the upper left-hand corner. Just be aware that when you click "OK" you will be prompted to change the settings of the current window or to modify the shortcut.
Exercise 3: Editing Features in the PowerShell Console
In the last exercise of this tutorial I want to introduce some editing features. I'm just going to list them and ask that you play around in the console until you are comfortable with how they work.
First, enter the following commands at the command prompt (for this exercise, what the code does is not important):
Locate and type the keys below on the keyboard, watch what happens.
- Page Up – Jumps to the first command in the history buffer.
- Page Down – Jumps to the last command in the history buffer.
- Up Arrow – goes back one command in the history buffer.
- Down Arrow – goes forward one command in the history buffer.
- Home – Jumps to the beginning of the command line.
- End – Jumps to the end of the command line.
- Ctrl+LeftArrow – goes to the left one word at a time. (In the console type – PowerShell tutorial lesson 1)
- Ctrl+RightArrow – goes to the right on word at a time. (In the console type – PowerShell tutorial lesson 1)
- Tab – Completes input (in the console type get-c and press tab, press tab again…).
- F7 – Shows history buffer (use the up and down arrow keys to navigate the buffer).
This concludes Lesson 1. When you feel comfortable with the material move on to the next lesson.Email This Page To A Friend