1

As we know, a Cmtlet maybe have a lot of alias,such as copy,cp,cpi always mean Copy-Item.So I want to make a alias table,it will like:

...
...
...
Copy-Item     copy,cp,cpi
Clear-Host    cls,clear
Move-Item     mi,move,mv
...
...
...

I can get all alias information use (Get-Command -CommandType Alias).Definition|Get-Unique to get the first column..But I don't know how to get the second colunm.

2
  • 1
    What have you tried, and how has what you've tried failed? SU is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See How to Ask a Good Question. Jul 13, 2017 at 14:24
  • Thanks for specify. I will do more research after post a question in this site.But anyway,I think the Group-Object can help me a lot.
    – yode
    Jul 13, 2017 at 14:31

2 Answers 2

2

If you want it sorted and without curly braces::

Get-Alias | Sort Definition | Group-Object Definition|
  ForEach-Object{"{0,-30} {1}" -f $_.Name,(($_.group.name) -join(', ')) }

Add-Content                    ac
Add-PSSnapIn                   asnp
Clear-Content                  clc
Clear-History                  clhy
Clear-Host                     clear, cls

Edit A variant which returns a [pscustomobject] instead of a formatted string:

Get-Alias | Sort-Object Definition | Group-Object Definition | ForEach-Object{
    [PSCustomObject]@{
        CmdLet = $_.Name
        Aliases =(($_.group.name) -join(', '))
    }
}

CmdLet                         Aliases
------                         -------
Add-Content                    ac
Add-PSSnapIn                   asnp
Clear-Content                  clc
Clear-History                  clhy
Clear-Host                     clear, cls
1
  • I'm prefer a without curly braces version indeed,It is just little complicated..:)
    – yode
    Jul 13, 2017 at 16:51
1
PS C:\> Get-Alias | Group-Object definition|ft name,group

will give what I'm after

Name                           Group
----                           -----
ForEach-Object                 {%, foreach}
Where-Object                   {?, where}
Add-Content                    {ac}
Add-PSSnapIn                   {asnp}
Get-Content                    {cat, gc, type}
Set-Location                   {cd, chdir, sl}
ConvertFrom-String             {CFS}
Clear-Content                  {clc}
Clear-Host                     {clear, cls}
Clear-History                  {clhy}
Clear-Item                     {cli}
Clear-ItemProperty             {clp}
Clear-Variable                 {clv}
Connect-PSSession              {cnsn}
Compare-Object                 {compare, diff}
...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .