powershellalias

Trying to create an alias to include options in powershell


My goal is to have an alias to run a command with -o at the end.

PS C:\Users\XXXX> vlab -o  <various different arguments>

I have tried to setup an alias, but Set-Alias recognizes -o as a parameter Option, and placing it in single or double quotes fails

> set-alias vlab 'vlab -o'
> vlab
vlab : The term 'vlab -o' is not recognized as the name of a cmdlet, function, script file, or operable program.

also setup a profile.ps1 with a function, but this just hangs when I run it.

Function VlabSpeed {
     vlab -o
}
Set-Alias vlab VlabSpeed

Is it possible to set an alias like this?


Solution

  • To recap:

    To incorporate arguments, you indeed need a function rather than an alias:

    If your short (function) name is the same as the base file name of the external program that it wraps, you need to disambiguate the two to avoid infinite recursion:

    Note: