Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpandProperty not showing other properties with Select-Object?

Tags:

powershell

I am having trouble with the -expand parameter of select-object cmdlet. I understand from the help file that I can get select-object to output the expanded properties and other properties, but that doesn't seem to be working in my case.

Following an example from the help file, the following works:

PS> Get-Process | select-object Name -expand Modules | fl
Name              : chrome
ModuleName        : chrome.exe
FileName          : C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
BaseAddress       : 10682368
ModuleMemorySize  : 868352
EntryPointAddress : 10980160
FileVersionInfo   : File:             C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
                InternalName:     chrome_exe
                OriginalFilename: chrome.exe
                FileVersion:      28.0.1500.72
...

Trying the same for what I want doesn't work though:

PS> Get-WmiObject Win32_ComputerSystem | select -Property __CLASS,__SUPERCLASS,__DYNASTY -expand __DERIVATION | fl
CIM_UnitaryComputerSystem
CIM_ComputerSystem
CIM_System
CIM_LogicalElement
CIM_ManagedSystemElement

As you can see only the contents of the expanded property are shown; everything else is skipped.

Here's the output without expanding the property:

PS> Get-WmiObject Win32_ComputerSystem | select -Property __CLASS,__SUPERCLASS,__DYNASTY,__DERIVATION | fl


__CLASS      : Win32_ComputerSystem
__SUPERCLASS : CIM_UnitaryComputerSystem
__DYNASTY    : CIM_ManagedSystemElement
__DERIVATION : {CIM_UnitaryComputerSystem, CIM_ComputerSystem, CIM_System, CIM_LogicalElement...}

Any suggestions on what I could be doing wrong or why this isn't working?

Thanks, Rakhesh

like image 208
Rakhesh Sasidharan Avatar asked Jul 23 '13 10:07

Rakhesh Sasidharan


People also ask

How do I get all the properties of an Object in PowerShell?

To get the object properties, the Get-member cmdlet is used in PowerShell. Specify a cmdlet, use the pipeline operator, and then type the Get-Member cmdlet to see all of the properties available from the specified command.

What PowerShell command selects specific properties from an Object?

The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array. To select objects from a collection, use the First, Last, Unique, Skip, and Index parameters.


1 Answers

It's by design. You need custom properties. try this:

Get-WmiObject Win32_ComputerSystem |
 select __CLASS,__SUPERCLASS,__DYNASTY,@{n="__DERIVATION";e={($_ | select -expa __DERIVATION) -join ',' }}| fl *
like image 182
CB. Avatar answered Sep 24 '22 20:09

CB.