Monthly Archive

Categories

select-object quirk

I was working with the new CIM cmdlets in PowerShell 3 CTP and mistyped a command (as I thought)

Get-Cimclass win32_operatingsystem | select -ExpandProperty methods | select -f 1 select -ExpandProperty Qualifiers

 

My surprise was because of the two uses of select without a pipe between them.  It works, I don’t know why – but I don’t recommend it Smile

2 Responses to select-object quirk

  • Alan says:

    This is because the last statement is equivilent to:
    Select-Object -First 1 @{l=’select’;e={$null}} -ExpandProperty Qualifiers

    So it is returning an empty ‘select’ field and expanding ‘Qualifiers’.

  • It`s effectively the same as:
    Get-Cimclass win32_operatingsystem | select -ExpandProperty methods | select -f 1 -Property select -ExpandProperty Qualifiers

    Trace-Command is your friend 🙂

    Trace-Command -name parameterbinding -expression {Get-Cimclass win32_operatingsystem | select -ExpandProperty methods | select -f 1 select -ExpandProperty Qualifiers} -pshost

    Which shows:
    BIND arg [select] to parameter [Property]

Leave a Reply