You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if you produce a ps1xml, you can create custom views (or override existing views) of a type (like System.IO.FileInfo). However, many types have common properties of the same type like TimeStamp being a DateTime but the format of that TimeStamp is specific to that type (including column width when used in a table). Would be great to be able to specify partial formatting so that you could keep the current format for the type, but just override a property. This way if formatting gets updated for that type, you inherit those changes, but your custom formatting for that property is retained. Similarly, you may want to override formatting for all DateTime properties of all types.
Reacted by Thomas Nieto, Keith Hill, PRASOON KARUNAN V and John Zabroski
Although by default I think it should be the previous (more regular) version. If you want the humanized version, maybe there should be a Format-Humanized command?
While my following example only works on PowerShell 5, I frequently want to use Format-Custom to view complex objects in reasonable ways. For example:
get-eventlog-LogName system -source "Service Control Manager"|where eventid -cin@(7000,7038) | select eventid,message,timewritten -Last 2|format-custom
The problem here is that the default serialization of DateTime in PowerShell is ridiculous. I end up with 142 useless lines of text. Compare the following brief log message to the one Format-Custom produces:
Ideal
class EventLogEntry
{
EventID = 7000
Message = The SSISScaleOutWorker140 service failed to start due to the following error:
%%1053
TimeWritten = Monday, July 8, 2019 12:08:46 PM
}
Actual
class EventLogEntry
{
EventID = 7000
Message = The SSISScaleOutWorker140 service failed to start due to the following error:
%%1053
TimeWritten =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date =
class DateTime
{
Date = 7/8/2019 12:00:00 AM
Day = 8
DayOfWeek = Monday
DayOfYear = 189
Hour = 0
Kind = Local
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 636981408000000000
TimeOfDay = 00:00:00
Year = 2019
DateTime = Monday, July 8, 2019 12:00:00 AM
}
Day = 8
DayOfWeek = Monday
DayOfYear = 189
Hour = 0
Kind = Local
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 636981408000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2019
DateTime = Monday, July 8, 2019 12:00:00 AM
}
Day = 8
DayOfWeek = Monday
DayOfYear = 189
Hour = 0
Kind = Local
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 636981408000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2019
DateTime = Monday, July 8, 2019 12:00:00 AM
}
Day = 8
DayOfWeek = Monday
DayOfYear = 189
Hour = 0
Kind = Local
Millisecond = 0
Minute = 0
Month = 7
Second = 0
Ticks = 636981408000000000
TimeOfDay =
class TimeSpan
{
Ticks = 0
Days = 0
Hours = 0
Milliseconds = 0
Minutes = 0
Seconds = 0
TotalDays = 0
TotalHours = 0
TotalMilliseconds = 0
TotalMinutes = 0
TotalSeconds = 0
}
Year = 2019
DateTime = Monday, July 8, 2019 12:00:00 AM
}
Day = 8
DayOfWeek = Monday
DayOfYear = 189
Hour = 12
Kind = Local
Millisecond = 0
Minute = 8
Month = 7
Second = 46
Ticks = 636981845260000000
TimeOfDay =
class TimeSpan
{
Ticks = 437260000000
Days = 0
Hours = 12
Milliseconds = 0
Minutes = 8
Seconds = 46
TotalDays = 0.506087962962963
TotalHours = 12.1461111111111
TotalMilliseconds = 43726000
TotalMinutes = 728.766666666667
TotalSeconds = 43726
}
Year = 2019
DateTime = Monday, July 8, 2019 12:08:46 PM
}
}
It is hard to unpack this comment as an outsider without spending a day playing around with PSMore.
I want a way to:
UnParse: data type -> string:
improve Format-Custom so that data types that contain cycles print succinctly/efficiently (either indirectly like DateTime.Date or directly like some domain object models implemented via ORM navigations)
Parse: string -> data type:
Take output and convert it back into .NET / PowerShell objects
This is really a bonus feature
Separately, I requested the Windows Console team implement "call by intention" escape code handling, such that console streams are structured objects and pipelines to-from programs are basically complex event processing engines. PSMore seems to tackle the problem "from within PowerShell" but not "across Programs", which was the original promise of "COM Object-Linking-and-Embedding".
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
iSazonov commentedon May 5, 2019
We could resolve this with PSMore #7857
rkeithhill commentedon May 5, 2019
RE
TimeSpan, PS 7 really, really needs a better default format for this this type because this is a bit of a spew:I would prefer to see this:
Or maybe the humanized version:
Although by default I think it should be the previous (more regular) version. If you want the humanized version, maybe there should be a
Format-Humanizedcommand?This is related to #9518 but more general.
jzabroski commentedon Jul 29, 2019
1 googolplex of YESes.
While my following example only works on PowerShell 5, I frequently want to use
Format-Customto view complex objects in reasonable ways. For example:The problem here is that the default serialization of DateTime in PowerShell is ridiculous. I end up with 142 useless lines of text. Compare the following brief log message to the one
Format-Customproduces:Ideal
Actual
jzabroski commentedon Jul 29, 2019
It is hard to unpack this comment as an outsider without spending a day playing around with PSMore.
I want a way to:
Format-Customso that data types that contain cycles print succinctly/efficiently (either indirectly like DateTime.Date or directly like some domain object models implemented via ORM navigations)Separately, I requested the Windows Console team implement "call by intention" escape code handling, such that console streams are structured objects and pipelines to-from programs are basically complex event processing engines. PSMore seems to tackle the problem "from within PowerShell" but not "across Programs", which was the original promise of "COM Object-Linking-and-Embedding".
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.