Powershell 别名似乎不适用于包含 -

Powershell alias doesn't seem to work with alias name that contains -

当我输入时:

Set-Alias -Name test2 -Value test

Get-Alias 显示要测试的 test2 点

但是

Set-Alias -Name test2-clone -Value test

Get-Alias 显示 test2-clone 但它不指向测试

虽然别名显示不正确,但设置仍然正确:

# 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

这是 C:\Windows\System32\WindowsPowerShell\v1.0\PowerShellCore.format.ps1xml

中定义的 commandinfo 类型对象视图中的一个(旧)错误

这是故意的,根据 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.