Alias pointing to script not visible


If I have an alias to a script file, I can't see the alias or the script through PowerTab. However, once it is typed in, I can get the parameters for it.

'param( [parameter()]$a) $a' > c:\temp\Get-TestScript.ps1
New-Alias Get-TestScript c:\temp\Get-TestScript.ps1

Results: <Nothing>
Expected: Get-TestScript

Looks like a simple modification in TabExpansionCore.ps1 to get it to work. In the "## Functions or cmdlets on dash" section with the Get-Command add "Alias" to the CommandType parameter.


JasonMArcher wrote Nov 23, 2010 at 12:56 AM

Aliases are completed with "Get-TestS@<TAB>". I'm not sure if I want to change that.

StephenMills wrote Nov 23, 2010 at 5:00 PM

Actually it doesn't resolve at all in the example you gave. You have to do "Get-TestScript@<TAB>". Then it resolves the alias to "c:\temp\Get-TestScript.ps1". Using "@<TAB>" is useful if you want to resolve an alias to the underlying command, but if the alias is a being used to redirect an old function/script name to a new name, then it isn't helpful.

In my case I am trying to get away from using scripts and move to functions. I decided I could start with an alias for all the scripts I currently have in my path and remove the path from $Env:Path. That way it doesn't have to hit the file system as much when running commands or looking them up. This lookup cost is worse in my case because the path is on a server over a 100mb Ethernet connection.

Current Env:Path


Create aliases based on files in directory

dir \Server\Scripts\PowerShell*.ps1 | % { New-Alias -Name $_.BaseName -Value $_.FullName }

Remove Share from Path

$Env:Path = $Env:Path.Replace(';\Server\Scripts\PowerShell', '')

Of course as soon as I do this, I can no longer do Tab completion on any of the scripts I used to be able to resolve with PowerTab.

Another example is the Resize-BitMap alias that comes with PSCX. It resolves to Set-BitMap. But with the way PowerTab is currently configured I can't use "Resize-<TAB>" to get the Resize-BitMap alias. And using "Resize-BitMap@<TAB>" sort of defeats the purpose if I am trying to find a Resize command.

Since it sounds like you don't have a lot of aliases that have a "-" in them, I don't think it would hurt you if this were added, but I believe it would help others and make it more consistent with what people would expect.


JasonMArcher wrote Apr 24, 2013 at 4:51 PM

Aliases are now shown with all other command types. Also, PowerTab will now show commands by default rather than file paths (so you don't need "-").

Implemented in changeset a968e46859dd.