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?

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
| improve this answer | |
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  
| improve this answer | |
  • Thank you postanote, for this question will go with the more direct answer as you have mentioned. By the way, your indentation of PS commands makes them much more readable, thank you. – Sabuncu May 31 at 7:14
  • 1
    No worries. My code formatting is because I'm old, and I need to make things as readable as possible. Yet, I've always lived by specific coding rules. If your code or comment line exceeds a normal page width (you know, 8.5x11), then it's too long and you need to break it up, using natural line breaks the language allows, or other techniques, like PowerShell Splatting. Some long lines are required, Slamming all on one line just because one can, does not mean you should. It's hard to read, troubleshoot, maintain. Just as bad is non-descript variable/function names and unnecessary punctuation. – postanote May 31 at 21:48
  • Well put, thanks. – Sabuncu Jun 1 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.