Tuesday, May 24, 2011

PowerShell 101 - OK - I guess I need to learn it

How to get started

Well, powershell is coming (it is already here we now have v3) so lets get up to speed quick.  If you are like me and don't want to learn another command line.  I started with JCL (mainframe) then came many variants of UNIX shells like the orginal bourne shell, or bash (UNIX, Linux)  Next was Novell and Windows with DOS commands and now powershell.  I asked many Microsoft evangelists, is powershell going to stay.  The answer is YES! So ok I guess I need to learn it.

Free book, yes a free book is built in, just right click the powershell icon in your toolbar and select Windows Powershell Help.

Lets start with cmd and then type powershell that is all it takes.  You can also find powershell on your task bar or search for it in your programs stash.  There you will find powershell and the ISE or Integrated Scripting Environment but more on that later. Now we are going to build some basic command that you should have in your library.  Let's start by getting help.

Help
 
To get help just type help and you will see that get-help is the cmdlet.  Notice the verb-noun relationship.  Remember back to early commands, dir, rm or format commands.  Are these safe commands?  Well if you look at first glance you might not know.  So you would need to type the command with /? to find out.  Remember format /? for example.  Strange way of getting help since you might not know the secret of /?.
 
Why not just type help or get-help that is exactly what you do in powershell.  The powershell verb GET is ok.  GETting is read only. OK I see, I think I am liking the new cmdlets. 
 
Type get-help and read.  Wow the help file is helpful.  Now type get-help get-command where get-command this the command you want help about. Yuck that looks like the old /? help from the DOS days.  Now type a better command get-help get-command -examples and note that powershell has examples that you can try, just copy and paste and you are ready to go.  Sweet..
 
What commands are available?  Just type Get-Help * to list them all.  Note several About_ listings, these are even more help on general concepts within powershell.  See all Get cmdlets by typing get-help get*  How about those variables, just type Get-Help about_variables

Are you a bad typist?
 
No problems since powershell has a TAB completion.  Tab completion is also a great feature from our Linux friends, just type in Get- and when you press the TAB key all the Get- commands will be scrolled through.  You can also use help as mentioned above.

History

Yes, PowerShell history.  Powershell does remember your old commands.  Just hit the up and down arrow keys and you can view your history.

Old DOS Hacker?

If you said yes then type in alias.  Alias will display the mapping from the old command you know to the new syntax used in powershell.  Check out dir, ls, and cls for fun.

Lazy Typist?

Texting in Powershell.  Since I am a lazy typist, I use alias to create abbreviation or shorted commands.  Just like texting on your phone.  OGV - Out-GridView

Your Basic Survival Command Library

Help Commands
Get-Help
Get-Help *
Get-Help Get-Command -examples
Get-Help about_variables

Get-Help get* or Get-Command | Sort-Object commandtype

More Info commands
Get-Command | Get-Member

Variables
get-help about_variables
$host.version

No comments: