Jared Tims
Jared Tims

Reputation: 349

powershell select-object property AND expandproperty

Trying to execute a Select-Object, but i can't seem to return property and a value from a key-value list property. There are 3 properties i want returned RunStart, Message and 'tableName' from this Parameters property.

I get too much with this:

|Select-Object -Property Parameters,RunStart,Message

Parameters                                    RunStart              Message
----------                                    --------              -------
{[tableName, AHROR012], [schemaName, dbo]...} 11/14/2019 5:39:06 PM Operation on target failed

But I dont get the RunStart or Message when i do this:

|Select-Object -ExpandProperty Parameters -Property tableName,RunStart,Message

Key                 Value
---                 -----
tableName           AHROR012

How do i do it to get:

Parameters.tableName                         RunStart              Message
----------                                    --------              -------
AHROR012                                      11/14/2019 5:39:06 PM Operation on target failed

THANKS!!!

Upvotes: 9

Views: 24383

Answers (2)

NitrusCS
NitrusCS

Reputation: 763

A more elegant solution would be to use a 2nd select statement:

... | select RunStart,Message -ExpandProperty Parameters | Select RunStart,Message,tableName

Upvotes: -2

Kamil
Kamil

Reputation: 106

... | Select-Object -Property @{
      Name='ParametersTableName';
      Expression={ $_.Parameters.tableName }
    }, RunStart, Message

Upvotes: 9

Related Questions