powershellpowershell-module

Powershell 5.1: alias descriptions are missing in my module


I have a module PhriInfrastructure which codifies our DevOps procedures at my organization. It has a function Test-IsLocalhost that I've aliased to Get-IsLocalhost for backwards-compatibility reasons.

I've tried to apply a description to the alias, like so:

New-Alias -Name Get-IsLocalhost -Value Test-IsLocalhost -Description "Get-IsLocalhost was renamed Test-IsLocalhost to better-match Powershell verb standards"

however, when I try to pull metadata about the alias in the command-line

Import-Module .\PowerShellModules\src\PhriInfrastructure -Force
(Get-Alias Get-IsLocalhost) | Format-List -Property *
Get-Help Get-IsLocalhost

the Description field is empty in both the Get-Help and the Get-Alias (the underlying Test-IsLocalhost command only has a #.Synopsis.

Meanwhile, if I attempt to create the alias direct from command-line, it appears in the alias members (but still not in the get-help).

Is there a way to expose the alias description properly? Or some better way to say "don't use this alias, use the primary one?" Is this just a bug in how Powershell 5.1 exports aliases in modules?


Solution

  • Indeed, whatever -Description value you specify seems to be lost when an alias is exported from a module (observed in Windows PowerShell and in PowerShell (Core) up to a least v7.3.6, current as of this writing).

    Is this just a bug in how PowerShell 5.1 exports aliases in modules?

    I'd say yes, and I encourage you to create a bug report in the GitHub repo.

    if I attempt to create the alias direct from command-line, it appears in the alias members (but still not in get-help).

    By design, aliases don't have their own help - Get-Help simply resolves an alias to its target command and shows its help, so you'll never get information about the alias itself that way.

    some better way to say "don't use this alias, use the primary one?"