Share via


Getting the sub properties of a property

Question

Wednesday, February 13, 2013 7:41 PM

I am reading a book on PS3 and there is an example that extracts what appears to me as a sub property of a property.

I am not sure how I can find out what sub-properties exist. Let me explain

**Get-Proces | Get-Member **  yeilds me the properties of the get-process cmdlet. One of those properties is StartTime.

Well the example the book lists is:

Get-Process | Select-Object -Property ProcessName,@{Name="Start Day"; Expression={$_.StartTime.DayofWeek}}

So I am struggling with how I could find out that the property StartTime has another property DayOfWeek.

How can I find this out?

I tried:

Get-Process | Select -Property StartTime | Get-Member

Basically I am trying to find out how I could determine if a property has might have other useful fields I can access.

All replies (5)

Wednesday, February 13, 2013 8:17 PM ✅Answered

**Get-Proces | Get-Member **  yeilds me the properties of the get-process cmdlet. One of those properties is StartTime.

Get-Process | Get-Member yields the properties of the output of the Get-Process cmdlet which is a System.Diagnostics.Process object.

When you look at that output, the Definition column lists the return types of all the methods and properties of the Process object.  All of them return types that have additional properties (except Void).

To further inspect types of properties with Get-Member, you need to pass that type into Get-Member.  In the case of StartTime, not all process objects have a non-null StartTime property, so you need to filter your output to get the information in the way you are trying:

Get-Process | Where {$_.StartTime} | Select -expand StartTime | Get-Member

Alternatively, you can just create a variable of that type and use Get-Member on it

[DateTime] $MyDateTime = Get-Dategm -i $mydatetime

You can also use the MSDN Library online reference for looking up methods and properties on types (assuming they are Framework Class Library types).


Wednesday, February 13, 2013 7:46 PM

If you look at the results of Get-Process | Get-Member and look at the StartTime property, you will see it is of type DateTime, so the DaysofWeek is a property of the DateTime object created and that object is stored in the StartTime property of the Get-Process object

If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.


Wednesday, February 13, 2013 7:54 PM

But how do you know that type DateTime has DaysOfWeek as one of its properties? That's where I am stuck. How do I query DateTime to find out what properties it may contain?


Wednesday, February 13, 2013 8:10 PM

Create a DateTime object by doing $test = Get-Date, then $test | Get-Member, you will see there is a DaysOfWeek property of type System.DaysOfWeek

If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.


Wednesday, February 13, 2013 8:36 PM

Thank you the select -expandproperty worked great. Exactly what I was looking for.