Skip to content

Commit 6827de5

Browse files
[release/v7.6] Properly Expand Aliases to their actual ResolvedCommand (#26571)
Co-authored-by: Ryan Yates <ryan.yates@kilasuit.org>
1 parent 2e04792 commit 6827de5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,21 +565,15 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag<string> errors)
565565
typeName,
566566
new PSScriptProperty(
567567
@"DisplayName",
568-
GetScriptBlock(@"if ($this.Name.IndexOf('-') -lt 0)
569-
{
570-
if ($null -ne $this.ResolvedCommand)
568+
GetScriptBlock(@"if ($null -ne $this.ResolvedCommand)
571569
{
572570
$this.Name + "" -> "" + $this.ResolvedCommand.Name
573571
}
574572
else
575573
{
576574
$this.Name + "" -> "" + $this.Definition
577575
}
578-
}
579-
else
580-
{
581-
$this.Name
582-
}"),
576+
"),
583577
setterScript: null,
584578
shouldCloneOnAccess: true),
585579
typeMembers,

test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" {
155155
$returnObject[$i].Definition | Should -Be 'Get-Command'
156156
}
157157
}
158+
159+
It "Get-Alias DisplayName should always show AliasName -> ResolvedCommand for all aliases" {
160+
Set-Alias -Name Test-MyAlias -Value Get-Command -Force
161+
Set-Alias -Name tma -Value Test-MyAlias -force
162+
$aliases = Get-Alias Test-MyAlias, tma
163+
$aliases | ForEach-Object {
164+
$_.DisplayName | Should -Be "$($_.Name) -> Get-Command"
165+
}
166+
$aliases.Name.foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue}
167+
}
158168
}
159169

160170
Describe "Get-Alias" -Tags "CI" {

0 commit comments

Comments
 (0)