PowerShell Equals Mechanism – Understanding Null Results

powershell

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?

Best Answer

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
Related Question