2

For the following PowerShell pipeline (based on this answer):

(Get-Command Get-ChildItem).Parameters.Values |
    where aliases |
    select Aliases, Name

I get a list of aliases and corresponding non-abbreviated switch-parameters, as follows:

Aliases  Name  
-------  ----  
{ad, d}  Directory  
{af}     File  
{ah, h}  Hidden  
{ar}     ReadOnly  
{as}     System  
{db}     Debug  
{ea}     ErrorAction  
{ev}     ErrorVariable  
{infa}   InformationAction  
{iv}     InformationVariable  
{ob}     OutBuffer  
{ov}     OutVariable  
{PSPath} LiteralPath  
{pv}     PipelineVariable  
{s}      Recurse  
{usetx}  UseTransaction  
{vb}     Verbose  
{wa}     WarningAction  
{wv}     WarningVariable  

When I change where Aliases as where Aliases -eq null to see those switch-parameters without a defined alias name, I get no results returned. I tried where Aliases -eq {} but that also produces no results. I know that switch-parameters without aliases exist; e.g. Force, Depth, Attributes and more.

How does the 'equals' mechanism work above?

Sabuncu
  • 486
  • 4
  • 10
  • 21

2 Answers2

3

The Aliases is always a collection. Use

(Get-Command Get-ChildItem).Parameters.Values |
   Where-Object {$_.Aliases.Count -eq 0} |
      Select-Object Aliases, Name
Aliases Name
------- ----
{}      Path
{}      Filter
{}      Include
{}      Exclude
{}      Depth
{}      Force
{}      Name
{}      Attributes
JosefZ
  • 13,855
1

Well, as we all know, there are various ways to get things done in PowerShell.

Here is a bit of a different approach to get the result for your use case. Yet JosefZ's answer is more direct. It's all a matter of preference.

(Get-Command Get-ChildItem).Parameters.Values | 
Select-Object -Property Name, @{
    Name       = 'Aliases'
    Expression = {$PSitem.Aliases}
} | Where-Object -Property Aliases -NE $null


# Results

Name                Aliases
----                -------
LiteralPath         PSPath 
Recurse             s      
Verbose             vb     
Debug               db     
ErrorAction         ea     
WarningAction       wa     
InformationAction   infa   
ErrorVariable       ev     
WarningVariable     wv     
InformationVariable iv     
OutVariable         ov     
OutBuffer           ob     
PipelineVariable    pv     
UseTransaction      usetx  
Directory           {ad, d}
File                af     
Hidden              {ah, h}
ReadOnly            ar     
System              as     



(Get-Command Get-ChildItem).Parameters.Values | 
Select-Object -Property Name, @{
    Name       = 'Aliases'
    Expression = {$PSitem.Aliases}
} | Where-Object -Property Aliases -EQ $null

# Results

Name       Aliases
----       -------
Path              
Filter            
Include           
Exclude           
Depth             
Force             
Name              
Attributes  
postanote
  • 5,136