2

When I type :

Set-Alias -Name test2 -Value test

Get-Alias shows test2 points to test

But with

Set-Alias -Name test2-clone -Value test

Get-Alias shows test2-clone but it doesn't point to test

1
  • So, what does it do? Anything? I don't see why that wouldn't work. Is test a function? What PowerShell version are you on? Commented Apr 27, 2022 at 13:50

1 Answer 1

2

While the alias does not display properly, it does still get set correctly:

# Set two examples
Set-Alias TestAlias -Value Get-Date
Set-Alias Test-Hyphen -Value Get-Date

# Doesn't display correctly from Get-Alias
Get-Alias Test*

CommandType Name                   Version Source
----------- ----                   ------- ------
Alias       TestAlias -> Get-Date                ## Works
Alias       Test-Hyphen                          ## Doesn't show command?

# Check the alias properties to see the command definition is set correctly:
Get-Alias Test-Hyphen | Select DisplayName,Definition

DisplayName Definition
----------- ----------
Test-Hyphen Get-Date  

# Use the alias, and it works fine:
Test-Hyphen

Wednesday, April 27, 2022 10:00:08 AM

This is an (old) bug in the View for commandinfo type objects defined in C:\Windows\System32\WindowsPowerShell\v1.0\PowerShellCore.format.ps1xml

This is on purpose, per the Get-Alias help page:

The output shows the -> format that was introduced in Windows PowerShell 3.0. This format is used only for aliases that do not include hyphens, because aliases with hyphens are typically preferred names for cmdlets and functions, rather than nicknames.

Sign up to request clarification or add additional context in comments.

1 Comment

Nice sleuthing. Since the bug still is still present in the current PowerShell Core version, I encourage you to file a bug at github.com/PowerShell/PowerShell/issues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.