[release/v7.6] Properly Expand Aliases to their actual ResolvedCommand (#26571)

Co-authored-by: Ryan Yates <ryan.yates@kilasuit.org>
This commit is contained in:
Aditya Patwardhan
2025-12-04 10:37:54 -08:00
committed by GitHub
co-authored by Ryan Yates
parent 2e047922ca
commit 6827de520b
2 changed files with 12 additions and 8 deletions
@@ -565,9 +565,7 @@ namespace System.Management.Automation.Runspaces
typeName,
new PSScriptProperty(
@"DisplayName",
GetScriptBlock(@"if ($this.Name.IndexOf('-') -lt 0)
{
if ($null -ne $this.ResolvedCommand)
GetScriptBlock(@"if ($null -ne $this.ResolvedCommand)
{
$this.Name + "" -> "" + $this.ResolvedCommand.Name
}
@@ -575,11 +573,7 @@ namespace System.Management.Automation.Runspaces
{
$this.Name + "" -> "" + $this.Definition
}
}
else
{
$this.Name
}"),
"),
setterScript: null,
shouldCloneOnAccess: true),
typeMembers,
@@ -155,6 +155,16 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" {
$returnObject[$i].Definition | Should -Be 'Get-Command'
}
}
It "Get-Alias DisplayName should always show AliasName -> ResolvedCommand for all aliases" {
Set-Alias -Name Test-MyAlias -Value Get-Command -Force
Set-Alias -Name tma -Value Test-MyAlias -force
$aliases = Get-Alias Test-MyAlias, tma
$aliases | ForEach-Object {
$_.DisplayName | Should -Be "$($_.Name) -> Get-Command"
}
$aliases.Name.foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue}
}
}
Describe "Get-Alias" -Tags "CI" {