Windows Vista Forums

Alias Replacement

  1. #1


    Mike Gale Guest

    Alias Replacement

    Has anyone developed a tool to replace aliases in code with the standard
    (verb-noun) names for cmdlets?

    (I'm thinking of something that will process a script, or console capture.)

      My System SpecsSystem Spec

  2.   


  3. #2


    Peter Schneider [MVP] Guest

    Re: Alias Replacement

    Hi Mike!

    As far as I know PrimalScript (www.primalscript.com) has support for
    expanding alias names to cmdlet names

    You could also use something like this:

    But: The used regex surly needs to be tweaked.... it's just a quick and
    dirty hack.. ;-)
    Also the alias names for
    ? --> where and % --> foreach are not expanded...


    # ------ save to
    resolve.ps1 ------------------------------------------------
    # usage: . \resolve inputFile.ps1 outputFile.ps1

    param ( [string] $inputFile,
    [string] $outputFile)

    begin {

    function resolveDefinition ( $aliasname ) {

    get-alias | where { $_.Name -eq $aliasname } | %{ $_.Definition }

    }

    }

    process {

    $aliasnames = (get-alias | sort Name -desc)

    (get-content $inputFile) | foreach {

    $result = $_

    foreach ($alias in $aliasnames) {

    if ($alias.Name[0] -match "[a-zA-Z]") {
    if($result -match "\b" + $alias.Name +"\b") {
    $result = $result -replace ($alias.Name),
    (resolveDefinition($alias.Name))
    }
    }
    }

    $result

    } | set-content $outputFile


    }

    #--------------------------------------------------------



    "Mike Gale" <MikeGale@discussions.microsoft.com> schrieb im Newsbeitrag
    news:E27439A1-A0FF-4EEA-9DD8-EB2460F194CD@microsoft.com...
    > Has anyone developed a tool to replace aliases in code with the standard
    > (verb-noun) names for cmdlets?
    >
    > (I'm thinking of something that will process a script, or console
    > capture.)




      My System SpecsSystem Spec

  4. #3


    Mike Gale Guest

    Re: Alias Replacement

    Thanks Peter.

    I like to suggest incorporating something like this into Community
    Extensions and eventually into Powershell itself.

      My System SpecsSystem Spec

  5. #4


    Keith Hill [MVP] Guest

    Re: Alias Replacement

    "Mike Gale" <MikeGale@discussions.microsoft.com> wrote in message
    news:CD452FF9-CF2F-45AD-B657-385D32D70F15@microsoft.com...
    > Thanks Peter.
    >
    > I like to suggest incorporating something like this into Community
    > Extensions and eventually into Powershell itself.


    FYI this is there if you use the PSCX profile. Well it is part of the tab
    expansion function e.g.

    > gal!<press tab> == expands to ==> Get-Alias


    --
    Keith


      My System SpecsSystem Spec


Alias Replacement
Similar Threads
Thread Forum
Get-Alias and its reverse PowerShell
Alias will like this Vista General
Ping Alias... Vista General
Set alias with parameter PowerShell
Reg:Alias Vista mail