[PS] new-alias and set-alias - why do we have both?

Discussion in 'Scripting' started by Andrew Watt [MVP], May 15, 2006.

  1. I suspect this has been asked before but why do we have both set-alias
    and new-alias cmdlets?

    Set-alias can create a new alias as well as changing the semantics of
    an existing one.

    So what function does new-alias serve?

    Andrew Watt MVP
    Andrew Watt [MVP], May 15, 2006
    1. Advertisements

  2. new-alias only creates a new alias if it doesn't already exist. It
    encapsulates the pattern "set if not set" so

    if ( -not ( test-path alias:foo )) { set-alias foo bar }


    new-alias foo bar -ea silentlycontinue

    Bruce Payette [MSFT], May 15, 2006
    1. Advertisements

  3. Wouldn't it be simpler just to add a -NoOverwrite parameter to

    Also the behaviour associated with your example is a potentially nasty
    one in my view.

    When, as is likely, aliases might be created by all sorts of scripts
    (or shared profiles?) a user might think he has set alias foo to mean
    X. But if foo exists already it remains Y (but the user is not

    If an alias foo already existed the user (or a script) may take
    subsequent actions on the assumption that an alias has just been
    created to have a specific meaning. Particularly with -erroraction
    SilentlyContinue in assorted places diagnosing the problem could be
    trickly in a complex environment, in my view.

    Andrew Watt MVP

    Andrew Watt [MVP], May 15, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.