Skip to content

Allow custom partial formatting #9538

Closed

Description

@SteveL-MSFT

Summary of the new feature/enhancement

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.

Activity

  1. added
    Issue-Enhancement
    on May 5, 2019
  2. iSazonov commented on May 5, 2019

    @iSazonov
    Collaborator

    We could resolve this with PSMore #7857

  3. rkeithhill commented on May 5, 2019

    @rkeithhill
    Collaborator

    RE TimeSpan, PS 7 really, really needs a better default format for this this type because this is a bit of a spew:

    05-05 11:27:19 1> Measure-Command { 6 * 7 }
    
    Days              : 0
    Hours             : 0
    Minutes           : 0
    Seconds           : 0
    Milliseconds      : 6
    Ticks             : 64564
    TotalDays         : 7.47268518518518E-08
    TotalHours        : 1.79344444444444E-06
    TotalMinutes      : 0.000107606666666667
    TotalSeconds      : 0.0064564
    TotalMilliseconds : 6.4564
    

    I would prefer to see this:

    05-05 11:38:01 26> [TimeSpan]"1.15:22:15.003",[TimeSpan]"0.0:0:0.015" | % { $_.ToString("G"); }
    
    1:15:22:15.0030000
    0:00:00:00.0150000
    

    Or maybe the humanized version:

    05-05 11:42:25 36> [TimeSpan]"1.15:22:15.003",[TimeSpan]"0.0:0:0.015" | % {[Humanizer.TimeSpanHumanizeExtensions]::Humanize($_,5)}
    
    1 day, 15 hours, 22 minutes, 15 seconds, 3 milliseconds
    15 milliseconds
    

    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?

    This is related to #9518 but more general.

  4. jzabroski commented on Jul 29, 2019

    @jzabroski

    1 googolplex of YESes.

    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
        }
    }
    
  5. jzabroski commented on Jul 29, 2019

    @jzabroski

    We could resolve this with PSMore #7857

    It is hard to unpack this comment as an outsider without spending a day playing around with PSMore.

    I want a way to:

    1. 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)
    2. 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".

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  9. added
    Resolution-No Activity
    on Nov 16, 2023
  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-No Activity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions