Saturday, January 7, 2012

Powershell (v2) - Parameter Aliases

To help speed things up when working with functions you can alias long, unwieldy, or, just plain painful Parameter names. Accomplishing this can be as simple as adding,
[Alias("youralias")]
to your function param definition. For example, I am adding a parameter named "t" to my function test below:

function Test {
  param(
    [Alias("t")]
    $test
  )

  return $test;
}

Test -T 1
When I run this I simply get back 1.

0 comments:

Post a Comment