I was scratching my head looking at a complex .NET object and wondering how to get all of the values out of it. For example:
$date = New-Object System.DateTime
$date | Write-Host # Because I was doing it remotely in a job
Monday, 1 January 0001 12:00:00 AM
And yet there are so many more properties available on the object:
$date | Get-Member
TypeName: System.DateTime # ... Snipped for brevity Date Property datetime Date {get;} Day Property int Day {get;} DayOfWeek Property System.DayOfWeek DayOfWeek {get;} DayOfYear Property int DayOfYear {get;} Hour Property int Hour {get;} Kind Property System.DateTimeKind Kind {get;} Millisecond Property int Millisecond {get;} Minute Property int Minute {get;} Month Property int Month {get;} Second Property int Second {get;} Ticks Property long Ticks {get;} TimeOfDay Property timespan TimeOfDay {get;} Year Property int Year {get;}
The solution was so, so simple, although none came up on a Google search:
$date | Select-Object -Property * # You can omit -Property
DateTime : Monday, 1 January 0001 12:00:00 AM Date : 1/01/0001 12:00:00 AM Day : 1 DayOfWeek : Monday DayOfYear : 1 Hour : 0 Kind : Unspecified Millisecond : 0 Minute : 0 Month : 1 Second : 0 Ticks : 0 TimeOfDay : 00:00:00 Year : 1
That's it. It would probably need to be more complicated in order to iterate any properties that need to be expanded (objects of objects). But I don't have an object complex enough to try it out on.