• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Alias Replacement

M

Mike Gale

#1
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 Computer

P

Peter Schneider [MVP]

#2
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 Computer

M

Mike Gale

#3
Thanks Peter.

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

My Computer

K

Keith Hill [MVP]

#4
"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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)