Understanding Powershell

Powershell is a very powerful language yet a lot of developers get frustrated by some of it’s little quibbles.
Learning a few little details make working with powershell much easier.

Items to consider are:

  • Continue On Error
  • Strict Options
  • Comparison Operators
  • Type System
  • The Pipeline

Powershell commands are always formed Verb-Noun although they can have a more familiar alias.

The beauty of Powershell is how configurable and reflective it is.
If you don’t like the default behaviour then it can easily be adjusted.

For example to find the automatic variables you can use the simple command:

dir variable::*

This lists the variables defined in global scope, including the automatic variables.
Details of these can be found using:

get-help about_auto | more

For example you can change the continue on error by setting $ErrorActionPreference

If you don’t think that PowerShell is strict enough on checking the parameters and types you can use:

Set-StrictMode -Version Latest

This is the Implicit None from Fortran (or VB’s OPTION STRICT).
It means that you get warned if you try to use an uninitialised variable.

PowerShell uses the prefix [Type] to define a type.

So:

$a = [int]16

is valid.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s