I’ve talked a little about Microsoft’s new command shell, PowerShell.  I’ve been using it for my day-to-day tasks at work.  There are some really great features for scripting and programming.  There are some bang on useful commands that will help with working with PowerShell.  Here’s a couple of things that will help with the *discovery* of PowerShell:
 
First up, get-member.  This nifty little command is used in conjunction with a pipe from another command.  What get-member does is list the members of the object(s) passed along the pipe from a previous command.  Woohoo!  RTTI for scripts!
 
Try this example:
PS C:> get-childitem | get-member

This will list all of the methods and properties of the object on get-childitem (aka dir or ls).

 

This leads me to the next darned useful thing, where.  Now that we know what can be accessed, the where command allows us to use it.

 
Try this example:
PS C:> get-childitem | where { $_.PSIsContainer }

This will list all of the containers of the given location.  It’s a very cool way to get a list of subdirectories for a directory.  Also in this example, notice the $_.  That syntax allow means ‘the current object’.  You can reference any property from

 

The last idea to leave with is the format- commands like format-table and format-list.  These allow you to build your own output formats for any command that emits an object.

 

Try this example:
PS C:> get-childitem | format-table Name, Length, PSIsContainer

This will take the get-childitem command’s output and only list the Name, File Length, and whether the child item is a container.

 

Can we say, Schweeeeet!?!

 

PowerShell’s name is appropriate, although *very* goofy.  I haven’t even touched the surface in my own personal uses, and I can see that this is the thing to learn.

 

More tips to come!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s