Group-object question

  • Let's suppose I have $objTable, a SQL Server table object, with 3 columns:

    nUnitType_Id

    cE_Descritpion

    cF_Description

    I swear that at one point a few months ago, this bit of code was returning $DescCols containing the expected 2 columns, but for the life of me I can't get it to work now... What am I missing here?

    $DescCols = $objTable.Columns | ?{(($_.Name).Substring(0, 3) -like "c[EF]_*") `

    -and ((group ($_.Name).Substring(3)).Count -eq 2)}

    $DescCols

    Thanks!

  • Figured it out.

    $DescCols = @()

    $MultiCols = $objTable.Columns | %{$_.Name.Substring(3)} | group | ?{$_.Count -eq 2}

    if ($MultiCols)

    {

    foreach ($Row in $MultiCols)

    {

    $DescCols += $objTable.Columns | ?{$_.Name -like "*$($Row.Name)"} | select name

    }

    }

  • Thanks for posting the answer you found for yourself. That may help someone someday. 🙂

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply