1

In an answer here on superuser.com, it is pointed out that gci -af is an alias for gci -File. That information is correct, and both command lines produce the same result of file listings.

However, I have not been able to find out a source of documentation where the -af alias is defined. For example, it is not defined in the primary documentation page for Get-ChildItem.

Is there another set of aliases for command line arguments when the command name itself is abbreviated, as in using gci for Get-ChildItem?

Sabuncu
  • 486
  • 3
  • 10
  • 21
  • If you go down on the documentation link, you will see that -Files alias' switch parameter is -af. – Reddy Lutonadio May 29 '20 at 13:38
  • @ReddyLutonadio You are right. In the browser I was surching for '-af' which was failing. Please post as answer so I can accept. Thanks so much. This has been bugging me for a while now! :) – Sabuncu May 29 '20 at 13:48

3 Answers3

1

Is there another set of aliases for command line arguments when the command name itself is abbreviated, as in using gci for Get-ChildItem?

There are several alias for the Get-ChildItem cmdlet.

enter image description here

Source: Notes

However, I have not been able to find out a source of documentation where the -af alias is defined. For example, it is not defined in the primary documentation page for Get-ChildItem.

The alias for -File parameter most certainly is defined in the primary documentation page for Get-ChildItem

enter image description here

Source: Get-ChildItem

Ramhound
  • 42,708
  • 1
    @PimpJuiceIT - If I had the ability to define a table I would provide text. Since that is not possible, and bullet points made my answer look ugly, I went with a screenshot instead. I could have made the first screenshot text, but I had already taken the screenshots, and I submitted it through my phone. – Ramhound May 29 '20 at 14:14
1

Down on the parameter lists of the documentation, you can find that -af is inded documented as an alias of -File.

-File

To get a list of files, use the File parameter. You can use the Recurse parameter with File.

Type:                                              SwitchParameter

Aliases:                                           af

Position:                                          Named

Default value:                                  None

Accept pipeline input:                      False

Accept wildcard characters:            False

1

All cmdlet and parameter aliases can be seen this way:

  • # Get named aliases:
      Get-Alias |
      Out-GridView -PassThru -Title 'Available aliases'
    

    Get cmdlet / function parameter aliases:

    (Get-Command Get-ChildItem).Parameters.Values | where aliases | select Name, Aliases | Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'

Another way of the above, but a bit different than your stated change, with the same results:

  • Function Get-CommandAlias
    {
      [CmdletBinding()]
    

    [Alias('gca')]

    Param ( [string]$CommandName )

    Get-Command $CommandName | Select-Object -expand ParameterSets | Foreach-Object { $PSItem.Parameters} | Where-Object { $PSItem.Aliases -ne $null } | Select-Object Name, Aliases -Unique | Sort-Object Name }

    gca -CommandName Get-Help

    Results:

    Name                  Aliases
    ----                  -------
    Debug                 {db}
    ErrorAction           {ea}
    ErrorVariable         {ev}
    InformationAction     {infa}
    InformationVariable   {iv}
    OutBuffer             {ob}
    OutVariable           {ov}
    PipelineVariable      {pv}
    Verbose               {vb}
    WarningAction         {wa}
    WarningVariable       {wv}
    

Yet another, before digging at parm aliases:

  • # Get a list of all commandlets for the specified name:
      Get-Command -Name '*Help*'  -CommandType Cmdlet |
      Out-GridView -PassThru -Title 'Available named cmdlet'
    

    Get-Command -CommandType Cmdlet | Where-Object { $PSItem.parameters.keys -match 'credential'} | Out-GridView -PassThru -Title 'Available cmdlets which has a specific parameter'

    Get a list of all functions:

    Get-Command -CommandType Function | Out-GridView -PassThru -Title 'Available functions'

    Get a list of all functions for the specified name:

    Get-Command -Name 'Help' -CommandType Function | Out-GridView -PassThru -Title 'Available named functions'

    Find all cmdlets / functions with a target parameter:

    Get-Command -CommandType Function | Where-Object { $PSItem.parameters.keys -match 'credential'} | Out-GridView -PassThru -Title 'Available functions which has a specific parameter'

    Get specifics for a module, cmdlet, or function:

    (Get-Command -Name Get-Help).Parameters (Get-Command -Name Get-Help).Parameters.Keys Get-help -Name Get-Help -Examples Get-help -Name Get-Help -Full Get-help -Name Get-Help -Online

    Get parameter that accepts pipeline input:

    Get-Help Get-ADUser -Parameter '' | Where-Object {$PSItem.pipelineInput -match 'true'} | Select-Object -Property ''

    Get property enums/options for a specifc cmdlet/function:

    1:

    (Get-Service | Select-Object -First 1).Status.GetType()
    [System.ServiceProcess.ServiceControllerStatus]::GetNames([System.ServiceProcess.ServiceControllerStatus])
    
    

    2:

    (Get-Service)[0].Status.GetType().GetEnumValues()
    (Get-ChildItem -Path $PWD)[0].GetType().GetMethods()
    
    

    List of all parameters that a given cmdlet supports along with a short description::

    Get-Help dir -para '*' | Format-Table Name, { $PSItem.Description[0].Text } -wrap

    List all loaded session modules and the exposed cmdlets / functions in them:

    Get-Module -Name '*' | ForEach-Object { Get-Command -Module $PSItem } | Out-GridView -PassThru -Title 'Available loaded modules and their cmdlets / functions'

    Get a list of specific cmdlets/functions in a module:

    (Get-Module -Name 'PSReadline' -All).ExportedCommands | Out-GridView -PassThru -Title "Available loaded modules and their cmdlets / functions"

JW0914
  • 7,865
postanote
  • 4,846
  • THANK YOU!. Your examples are absolutely out of this world. For your second example, prior to piping the results to Out-GridView, I changed the display order as: select Aliases, Name and added | sort Aliases, which allowes me to see the results indexed by alias. Again, incredible answer, thank you once more. – Sabuncu May 30 '20 at 08:18
  • 1
    No worries, glad it provided a little more to chew on for you. I teach PS courses/sessions/talks to my internal teams, customer sites, etc. So, I am always pressing must attendees to master use all the help PowerShell can spin up. What I gave is a small snippet of a much larger file [Consolidated PowerShell Help Resources and Options.ps1 - currently almost 3208 lines of info that I regular modify as needed] I give to my attendees and I encourage them to tweak it as they see fit or of course use it as is. Check the samples just added for you. – postanote May 30 '20 at 08:46
  • I am going to post another question based on your second example, and would like you to please look at it. I am not adding it here as a comment, so that you can get credit, and to comply with the rules of the site. – Sabuncu May 30 '20 at 08:49
  • Thank you for the additional content. Here's that question I just posted: https://superuser.com/questions/1556393/how-does-the-equals-mechanism-work-in-powershell-to-see-null-results – Sabuncu May 30 '20 at 09:08
  • 1
    Hey, Sabuncu, no worries, and I just got on the site today to see this. I saw others have already responded to you on this and the JosefZ is the most prudent and the way I would have responded. As for getting the credit, well, I get them if I answer early enough in most cases, but these folks got to you first. ;-}, so, only fair to award to whoever gives you the most appropriate answer. But I did provide another approach, well, just becasue. ;-} – postanote May 30 '20 at 23:19
  • Postanote, I think you should put together a video training course on PowerShell, if you haven't done so already. – Sabuncu May 31 '20 at 08:09
  • I have done such things as custom course for my team and customers, but not anything public. I have folks ask me to spin up a Youtube channel and do that as well. I just never got around to it. I've been and MCT (Microsoft Certified Trainer) for a little over 2+ decades and have taught many of the MS PowerShell MOCs' as well as the PowerShell courses. [https://www.microsoftondemand.com/courses/microsoft-course-10961 and https://www.microsoftondemand.com/courses/microsoft-course-10962]. They are still good for folsk today as well. – postanote May 31 '20 at 21:39