Scripting Man’s best friend – PowerShell

In the world of GUI, at the heart, I am still scripting / command line / shell man.

No matter how GUI application is built, there can be no efficiency and repeatability like in a powerful, versatile script.

In the beginning, there was DOS. Than simple Command processor of Windows 95/98 (I resisted of installing Windows ME, thank God for that). Than, enlightenment – JP‘s 4Dos (retired) and 4NT – the way CMD should be from start. 4NT was breakthrough in my productivity – backup, maintenance, monitor scripts; processing of folders and files; automating each and every boring repeatable action. Add on top of that AWK for really complicated stuff and there was no problem without solution.

Microsoft was aware about all of shortcomings of CMD shell and tried to overcome them introducing Windows Scripting Shell; however, that approach simply was not successful.

Than MS started to work on Microsoft Shell or MSH (codenamed Monad), and first public beta was in September 2005. Finally, they renamed it to Windows PowerShell and build one of the most powerful scripting system for all kinds of tasks – from simple file operations to management of domains and networks. With PowerShell you can manage files, folders, remote locations, registry items, COM objects …

Let’s see how dir command does both in PS and CMD:

PowerShell dir command

What is the difference? (apart from obvious: colors and different way of displaying information) Real difference is that result of the CMD dir command are lines of text and result of PS dir command are objects; objects which you can query for attributes and to decide what to do next based on attribute values.

  • Commands are not text-based – they deal with objects
  • Command family is extensible – native binary commands, cmdlets (pronounced command-lets) can be augmented by cmdlets that you create

For example, to find out all properties of objects returned with dir, execute:
dir | get-member

By the way, dir is not real name for cmdlet – it is just an alias:

PowerShell Get-Alias dir

You can create your own aliases using the Set-Alias cmdlet.

Just one important thing if you plan to dive into PowerShell scripts world:

In order to create and use scripts, instead of just inline commands, you need to deal with security. More info can be obtained with
* get-help about_signing | more
* get-help Set-AuthenticodeSignature -detailed | more

(or redirect this to file and read afterwards)

(basic help can be obtained for any cmdlet with “-?“; detailed help can be obtained with “get-help cmdlet-name“)

Almost forgot – real reason for this post was that PowerShell reached version 1.0 and it is availabile for download.