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 Intro…

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:

  1. 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.
  2. 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 Concepts

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

PowerShell Console Graphic

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

  1. Create the following directory – C:\MyScripts.
  2. Create a PowerShell shortcut on your desktop.
  3. Right-Click on the shortcut and choose Properties.
  4. Under the Shortcut tab locate the Start in: text box. Type in the path to the folder created in step 1. C:\MyScripts
  5. Click Ok.
  6. Launch PowerShell from the desktop shortcut.

 PowerShell starts in the directory path we've chosen: PowerShell Console MyScript

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.

  1. Right-click on the shortcut and choose Properties.
  2. Choose the Colors tab.
  3. 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.
  4. Set Screen text to yellow, Screen background to blue.
  5. Launch PowerShell from the desktop shortcut.

PowerShell runs in the colors we've chosen:
PowerShell Console Colors

 

Next I'm going to make the text larger so I don't have to squint.

  1. Close the PowerShell Console by typing exit.
  2. Right-Click the PowerShell shortcut and choose Properties.
  3. From the Fonts tab, choose 12 x 16. Click OK.
  4. Launch PowerShell from the shortcut.

Do you see the following? I mean can you really see it now?
PowerShell Console Large Font

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):

get-acl <enter>

get-alias <enter>

get-command <enter>

get-date <enter>

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 Email This Page To A Friend

Comments

Thanks for a great site. It’s already in my PowerShell Favorites folder. I need to get a grasp on this new shell very soon and I’m gathering as many online resources as I can.

Anyway, the popup colors for text and background only change the colors for the History Buffer popup box, not the error messages from the shell.

Yeah, great site! The world is a better place because of this site :)
I too am trying to learn PS. The popup colors for text and background worked great for me for both error messages and the history buffer.

P.S. In honor to my very first computer monitor, I set the shell’s background to black and the text to orange. Ode to the good ol’ days with my Commodore 128! :-)

hrp2171 thanks for the good catch, I’ve edited the tutorial to reflect the change. Glad to hear you guys are enjoying the site! As a reminder, besides bookmarking the site, you can sign up for email notifications which will send an email when new topics, articles, and tutorials are posted to the site. Click here to find out more.

This site really rocks!

Thank you for the time … effort … and for sharing your knowledge!

:)

Looks better and easier to understand than other tutorial sites i have read. And like sammzn’s commnent: Thank you for your time, effort and sharing your knowledge!!

Yeap!

What a way to help… The Clear text, clear path, just ROCKS!
The simple way to transfer Knowledge, thanks MVP!

Thanks for the tutorial, I need to get up to speed on this fast.

Yes, a great tutorial.
And it is for free.
Thnx to Jesse :-)

I love this site!

Great resource many thanks to the folks maintaining it.

Good job, other than some HTML I dabbled in earlier this year I am just beginning to explore programming. Your site offers comprehensive instructions abut PowerShell that even a basic beginning user can grasp.

What is DUI?

Off topic but just a query about DST on Windows 2000…
Did anyone else create an MSI with the updates and deploy that? I know it adds stuff to the installed apps list and would require an update MSI if there are future changes but I found by creating an MSI I could leverage of existing deployment technologies.

How do we move on to the next lesson? Can’t find a next or a label with lesson 2.

How do I get to the second lesson?

Is there a tutorial for deleting files, renaming, getting the computer IP number, formatting a USB drive etc pls?

Thanks for this very usefull tutorial.

Thanks from the Netherlands… :D

yo… tutrial seems to be interesting… how do i get to lesson 2?

use this google search
site:www.powershellpro.com intext:”PowerShell Tutorial 2″

replace 2 with whatever one youre after.

this tut is wkd so far. newcomer to powershell so yay! i miss the old batch days and some form of CL on windows that actually rocks has got me all happy :D

All lesson links are in the side-bar and they go in order from top-to-bottom.

Hope that helps…

DUI =? Driving under Influence

lol

One more thank you for the good work! ;)

As a newbie to powershell, I love the site

No, the list of pages in margin is alphabetic by topic not by tutorial number. Thank goodness for google.

The GUI (pronounced goo-ey) just won’t DUI (pronounced like goo-ey)
:P
cheers

Very nice introduction! Thank you.

I feel as if I have taken my first step into a larger world!

Thanks!

Nicely documented…

Thanks so much,it’s a great opening into another world!

“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 ”

You apparently don’t know Unix/Linux. Unix was designed from the start to pipe output from one command into another to produce *very* useable results.

I just tried a few commands and was disappointed (why was I optimistic?). If you know Unix/Linux shell programming, be prepared to be frustrated. Powershell is the usual Microsoft over-promoted attempt to make something useful.

In Unix, the tee command is simple and effective. I saw that Powershell has a tee command and thought “they’ve seen the light!”. I was wrong. The Unix tee command has a switch “-a” that tells tee to APPEND the input to the output file; Powershell’s tee doesn’t have this functionality, making it MUCH less useful.

I haven’t explored Powershell very far but can anticipate that it will not be nearly as useful as the Bash, Korn or other Unix/Linux shells. Powershell’s main value will be in its ubiquity (but only in the Windows environment, of course).

By royal charlie on October 22nd, 2010 at 3:41 am

yeah yeah! unix shell ie. bash is great but you won’t be able to use it in the windows environment?!?! Obviously, ps is the best for this.. so stop comparing. Thanks for the great tutorial dude!

By Mohamed Sameer on November 21st, 2010 at 3:31 am

great work
i am going to go through the entire tutorials soon
thanks

By TechnoRoyal on December 23rd, 2010 at 3:12 am

Awesome Article !!

Good Stuff

Awesome..thanks a ton…..

Many thanks for such an amazing resource. Currently working my way through it.

Hope the rest of the tutorials don’t give me this “duh! ofc” feeling. You just explained doskey/pif stuff carried over to win98 …
Well that and the difference between my batch world and modern windows scripting.

ps. You really need a better menu system. This one is hard to use on my windows phone as zooming in on text makes it disappear.

Good Startup for beginners.
Thanks
Jeevan

By Paul Brewer on February 16th, 2011 at 2:07 pm

Kudos! Merci! Gracias! Many thanks! Whatever language you need it in – this is extremely helpful for those of us who are new to the subject.

Thx for providing such a wonderful help and knowledge for beginner

By Nikita6003 on March 4th, 2011 at 12:41 am

Yippee! Have just been told to drop VBScript and start using PS – tnx to this site I can start my weekend without worrying about it too much

^_^

This tutorial is great but why there is no quick link to the next tutorial?

So, for 3 years, just lesson 1 – how to open the console ?… r’u kiding ?!…

@Tom

to DIRECT the output of a command to a file try a chevron >

to APPEND the output of a command to a file try 2 chevron >>

example:
ps >c:\ps.txt (this will create or overwrite ps.txt on the root of your C drive)

or

ps >>c:\ps.txt (this will append onto the end of ps.txt on your C drive)

Iv not looked at the tee command yet, but do remember doing this stuff on a dumb unix terminal years ago. Just tried in powershell, still works.

I like the idea of command output being an object. I am also looking forward to getting to grips with powershell. I got into computing as i like things that advance\progress and dont get stagnent(for want of a better word). I dont think we should compare powershell to any other shell out there. They all will have followers and haters. Choose the one you either like or want to learn. I think we all like and feel most comfortable with the ones we cut our teeth on. Like the man who liked the blue background and yellow txt of his C128. I have set mine to a black BG and orange txt.

thanx v-much for sharing your knowledge, finding these tutorials well written and really informative. for those peeps that cant navigate their way round a website saying “i cant find the… whine whine whine”. If you can even find the tutorials, unplug your computer, put it back in the box and send it back where it came from. then go buy a shovel(digging implement) and some steel capped boots !!!

COMPUTING IS NOT FOR YOU MY FRIEND , psml

thanks

auldy

for those peeps that cant navigate their way round a website saying “i cant find the… whine whine whine”. If you can even find the tutorials,

meant to say”cant even find tutorials”

Auldy

Very easy to understand. Thanks!

Where does Powershell 2.0 put its group during installation? It doesn’t appear in the group specified in this article.

This is good for my first time experience

I have to do just a bit more than the old DOS-batch-language makes possible. Hope PS will be easy enough.
Thank you, Jesse Hamrick. Your site is promising!

Great article. Ir really helped in kickstarting powershell in no time.

Great tutorial for first time experience.
keep up the good work !!

its really good for beginers and thanks for the effort.

Really Helpful tutorial
Good Job

Lets see what we have in next chapters as well

2.Create a PowerShell shortcut on your desktop.

how?

Echo Paul’s question. Power shell is not listed as a program, but I can run it from the program search on Win 7. I don’t know what file to look for and where.

So how can I create the shortcut?
2.Create a PowerShell shortcut on your desktop.

By Terry Gallo on December 23rd, 2011 at 8:13 am

I am attempting to load the Prerequisites for Exchange Server 2007 onto Server 2008.

I have downloaded these files, created a directory C:\PreReq and unzipped the files to this directory.

From a Cmd prompt at C:\PreReq I use the command ServerManagerCmd –ip Exchange-Base.xml

Mt Cmd prompt window states the following error:
“ServerMangerCmd.exe. is deprecated, and is not guaranteed to be supported in future releases of Windows. We recommend that you use the Windows PowerShell cmslets that are available for Server Manager.

..
ArgumentNotValid: Features not valid: ‘PowerShell”. The name of the feature was not found.”

I have installed PowerShell, changed directories to: PS C:\PreReq>

What is the syntax to run Exchange-Base.xml?

In researching this it appears I can build and run the entire world using PowerShell, but that is not germane to me at this moment. I am building a lab environment in VMWare and just need one command line.

Thanks

Terry Gallo

By Terrill Settles on January 2nd, 2012 at 10:56 am

The Windows Powershell (if you did a search) in Windows 7 is at c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe

amazing article. Thank you

Have you ever seen the behavior where you have the starting directory set but when you right-click and Run as Administrator it starts in C:\Windows\system32?

By Henry Jaafari on February 8th, 2012 at 11:27 am

I liked it…and im ready for the next lesson already…bring it on..

Great tutorial!

For anyone using Win 7 and you are having problems creating the desktop shortcut, try this: click the Start button, type PowerShell, right-click Windows PowerShell, go to “Send to” and click on Desktop (create shortcut). It took me a while also, but I eventually got it so I wanted to share.

Just wanted to add on to the
“Tab – Completes input (in the console type get-c and press tab, press tab again…).”
If you hold Shift and press Tab it reverses the direction of the search.

By Boyd Stan on March 14th, 2012 at 7:16 pm

I want to put a ding within the universe.
Reason and judgment are the qualities of the leader.

One shouldn’t have to be jackin with the DST settings. That’s why we use NTP at the server level and is NPT’s other sole job to handle time setting. Just an observation.

Can I suggest a Next-Lesson and Prev-Lesson link at the bottom of each lesson?

By Tamara D on May 1st, 2012 at 2:14 pm

WOW! such a great start. I loved tutorial 1. I cannot wait for 2 through…… Thank you so much. By the by, the reason people say they cannot find the tutorial is when you select the link on the right it takes you right back to the Enstien picture and the intro. All it says at the bottom is email a friend. It seems people do not realize tutorial is the second link. It took me a minute. Anyway thought I would share. Really a great job. I thought I would share one typo with you as you said you wanted feed back. Not really worth mentioning with something so clear and consise. Cntl+right arrow “one” not “on”. Thanks again.

awesome, thanks for taking the time

I too was confused as to how to find the tutorials. If you still update this site, it’d be a great help to simply have links at the bottom of each one (including the intro) that say: Previous Tutorial and Next Tutorial

Great site, good work. Thanks.

By Reggie S on June 3rd, 2012 at 4:34 pm

Thanks for putting up this repo of material for learning PS! Just my 2 cents on comparing PS with the other scripting technologies, ofc we should always compare – just constructively though. Finding faults in a scripting system is a sign that there is room for improvement for it, right? PS just has not matured as much as the other scripting techs but the PS core developers should try out the well-used scripting techs so that they can also apply what works for PS which is a win-win solution for all IMHO.

Create the following directory – C:\MyScripts.
Create a PowerShell shortcut on your desktop.

How to do this?

These questions will tell ya how new i’m to PS

Thanks

I am new to ps and like this site. In this lesson, at the end, it mentions:
“Page Up – Jumps to the first command in the history buffer.” along with other cmds but I’m not seeing what I should expect.
Call me a newbie to ps but how do I get these page up, page down, etc. cmds to work in ps?

By Chris Quirke on August 22nd, 2012 at 3:35 pm

@Lori – yes, I can imagine that happening because that also happens as a bug when launching Windows Directory Statistics as a non-default action associated with Drive (i.e. HKCR\Drive\Shell\Statistics\Command=…), when the target is C: and the OS is Vista or 7.

By Chris Quirke on August 22nd, 2012 at 3:40 pm

@Jay Rechek – on creating a shortcut to Powershell, I was surprised to find just typing in “powershell.exe” as the target (with no path) “just worked”, saving me from having to worry where the executable was.

The shortcut has Properties rather like a Win9x-era .PIF but is a .LNK, the Properties pass through from the target I think.

By Richard Hayes on September 22nd, 2012 at 3:47 pm

Even an old (69) DOS guy like me is enjoying the learning experience of this tutorial. Thanks for the great job.

Impressive tutorial, attractive approach! keep going!

Excellent Material.

It is Excellent.., No doubt. Can anyone share the link for Tutorial-2.

Rgds,
Abdul

Absolutely great. Awful site navigation! Cant find anything, but great content.

Awesome Site!

thanks!this is really interesting and practical. My worry: where are the links to the other tutorials? could someone mail me the whole tutorial at anyujeff@gmail.com??

By Daniel Sandberg on February 21st, 2013 at 4:21 am

This is really pedagogically formulated. Nice job.

By Rakesh Varma on April 2nd, 2013 at 4:56 am

@jim : you can find the powershell at c:\windows\system32\windowspowershell\v1.o\powershell.exe
right click on it and send it to desktop it will create a short cut for you.

Great site. I am just starting to learn Powershell.

I have tried working for individaul server not multiple servers(dynamically servers has to pick and result has to come in csv format)
Get-WmiObject Win32_Volume -Filter “DriveType=’3?” | ForEach {
New-Object PSObject -Property @{
Name = $_.Name
Label = $_.Label
FreeSpace_GB = ([Math]::Round($_.FreeSpace /1GB,2))
TotalSize_GB = ([Math]::Round($_.Capacity /1GB,2))
}
}

Thanks and good work.

Its a nice and simple tutorial for a very beginner like me. thanks a lot

Great Resources.

Thanks for sharing :)

Thanks for putting the time into the tutorial :)

One minor point: I would have talked about the escape character in PowerShell Tutorial 1 : Configuring the PowerShell.

I had a directory “[sometext]”.
I had to discover the Powershell specific syntax:
> cd ‘.\`[sometext`]‘

thanks

Thanks dude for the great introduction. I’m new to PS and this helped me understand what it is.

Very helpful site. Thank you for providing content.

OK. I too would like to thank the publisher for the time, effort and consideration they’d put into this site. However, for those of you, the self rightous, the presumptous such as aul%$, suggeting to people tat if they cannot find the tutorials then they should’nt be on this site. Really? And how many of you you faked it until you found out the same info that was posted except now you sound your horn of “I am anism”! PLEASE! To the author; yes it is rather an obscure guess for one to immediately discern that the next in line is “intro to the console”…and so on and so on. You do alot of good. You make it interesting when other major intro sites couldn’t. Why not make the navigation just a bit more friendlier. It would only tak a bit more time. For the others…relax, no one is bitchin, just searchin.

You are a rockstar Jesse..Thanks for sharing the knowledge.

Great tutorial… Thanks for taking the time to create and present this material :)

Really awesome tutorial dude. Thanks a lot and keep giving stuff like this

Thanks for sharing the knowledge. If I may offer one clarification for “Exercise 3: Editing Features in the PowerShell Console”. Start by introducing the “history buffer”, followed by entry of the four commands and then present “F7 – Shows history buffer (use the up and down arrow keys to navigate the buffer)” as the first of 10 rather than the last of 10 key behavior examples. Also grouping the key behaviors into “history buffer” behaviors and PowerShell console behaviors might avoid some confusion. I was beginning to think my keyboard keys were incorrectly mapped before discovering the “history buffer” {F7} on the last step. (my KBU is a Dell SK-8165).

By Sagar P Dalvi on March 7th, 2014 at 11:01 pm

thank you sir

Very Nice. Thanks.
Small suggestion…
Under the locate and try these keys;
add:
Esc (escape) key
dismisses popup window

:)

Awesome site. Thank u so much for putting in all the effort.
Each point is explained so clearly, its great.

By Mohammad Hossain on September 1st, 2014 at 9:31 am

Thanks for your effort. Awesome site.

Hi
my name is varun kumar. I am getting a pop up that windows powershell has stopped working, wenever i try to open any file in my system.And the pop up is keep on displaying even i close it.
Please help me with a solution.

 

Leave a Comment