Document the $PSStyle.HumanReadable settings for human-readable file sizes and timestamps (PowerShell 7.8)

Offen Anfängerfreundlich
#13,407 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Dokumentation
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
powershell
Bereich
documentation

Rechercherichtung

Beginne mit den im Issue genannten PowerShell-7.8-Referenzseiten: about_ANSI_Terminals.md und Get-ChildItem.md. Dokumentiere die drei Einstellungen von $PSStyle.HumanReadable, ihre Standardwerte und Auswirkungen und erkläre, wie sich rohe Byte-Anzahlen wiederherstellen lassen; aktualisiere die zitierten Verzeichnislisten-Beispiele, sobald der 7.8-Ordner verfügbar ist. Fertig ist die Arbeit, wenn die Referenzseiten das Verhalten beschreiben und die Beispiele den neuen Standard widerspiegeln.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Prerequisites
  • Existing Issue: Searched the existing issues for this repository; there is no issue covering the new $PSStyle.HumanReadable members (the closed issues only cover AutoSizeDefaultFormatting, CustomTableHeaderLabel, and Progress.View).
  • Descriptive Title: See above.
Summary

PowerShell is adding a $PSStyle.HumanReadable nested settings object in PowerShell 7.8 that controls whether certain formatted values are rendered in human-readable form. The documentation needs to cover the three boolean settings and their defaults — most importantly that the Length column of directory listings (Get-ChildItem / Get-Item) now shows sizes like 820.1 MB or 1.1 TB instead of raw byte counts by default, and how to restore the previous display.

Details

The feature was requested in PowerShell/PowerShell#24011 (with the Working Group decision defining the $PSStyle.HumanReadable surface) and is implemented in PowerShell/PowerShell#28468 (targeting master, so it ships in PowerShell 7.8 - it is not part of the released PowerShell 7.7). Design proposals that informed the formatting choices are in kilasuit/PowerShell#171.

$PSStyle.HumanReadable has three boolean properties:

  • Size (default $true): file sizes in directory listings render in compact binary (1024-based) units with at most one (truncated) decimal digit, similar to Windows File Explorer:

    # PowerShell 7.7 and earlier            # PowerShell 7.8 (default)
    Mode  LastWriteTime         Length       Mode  LastWriteTime       Length Name
    ----  -------------         ------       ----  -------------       ------ ----
    -a--- 04/07/2024 01:36      859832320    -a--- 04/07/2024 01:36  820.1 MB backup.vhdx
    -a--- 04/07/2024 01:35           776     -a--- 04/07/2024 01:35    776 B BackupSpecs.xml
    -a--- 04/07/2024 01:36 1298450612224     -a--- 04/07/2024 01:36    1.1 TB disk.vhdx
    
  • Datetime (default $false): when enabled, the LastWriteTime column renders relative timestamps - just now (less than a minute), 5 min ago (less than an hour), 19 hours ago (less than a day), 6 days ago (less than 7 days). Values older than 7 days, or in the future, fall back to the existing culture-aware short date and time format.

  • Timespan (default $false): reserved for follow-up work on System.TimeSpan views; currently has no effect.

Behavior worth documenting:

  • The setting is honored at render time; changing it takes effect immediately without reloading format data.
  • Only display formatting is affected - the Length (Int64) and LastWriteTime (DateTime) properties of FileInfo objects are unchanged, so scripts that read the properties are unaffected.
  • Files not on disk (FileAttributes.Offline) keep the existing parentheses convention, now humanized: (2 KB).
  • Setting $PSStyle.HumanReadable.Size = $false restores the raw byte count display of earlier versions.
  • The default formatted view of $PSStyle lists the new settings (HumanReadable.Size, HumanReadable.Datetime, HumanReadable.Timespan).
Articles

The reference updates target the reference/7.8 version folder, which is created upstream when the PowerShell 7.8 preview documentation cycle begins:

  • about_ANSI_Terminals (reference/7.8/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md) - the $PSStyle deep dive
  • Get-ChildItem (reference/7.8/Microsoft.PowerShell.Management/Get-ChildItem.md)

In addition, examples elsewhere in the docs that show Get-ChildItem output with raw byte counts render differently under the new default (for example, the $WhatIfPreference examples in about_Preference_Variables show 10 test.txt in the Length column, which now displays as 10 B). These example outputs can be refreshed when the 7.8 version folder is created.

Suggested updates
  1. Add HumanReadable to the bulleted property list of $PSStyle in about_ANSI_Terminals, noting it was added in PowerShell 7.8.
  2. Add a $PSStyle.HumanReadable detail block to about_ANSI_Terminals alongside the existing AutoSizeDefaultFormatting / Formatting / FileInfo blocks (suggested content below).
  3. Add a note to the OUTPUT section of Get-ChildItem (and optionally Get-Item) that file sizes are displayed in human-readable format by default and can be restored to raw byte counts with $PSStyle.HumanReadable.Size = $false.
  4. Refresh example outputs that show directory listings with raw byte counts when creating the 7.8 version folder.
Suggested content

New entry for the $PSStyle property list in about_ANSI_Terminals:

  • HumanReadable - Nested object that controls whether values such as file sizes and timestamps are rendered in a human-readable format (added in PowerShell 7.8)

New detail block for about_ANSI_Terminals:

  • $PSStyle.HumanReadable is a nested object that controls whether certain
    values are rendered in a human-readable format.

    • Size - A boolean, defaults to $true. When enabled, file sizes in
      directory listings (such as Get-ChildItem and Get-Item) are displayed
      in compact binary units, for example 745 B, 16.7 KB, 820.1 MB, or
      1.1 TB, instead of raw byte counts. Files that aren't available on disk
      are shown with their size in parentheses, for example (2 KB). Set this
      to $false to restore the raw byte count display. This only affects
      formatting; the Length property of FileInfo objects is unchanged.
    • Datetime - A boolean, defaults to $false. When enabled, timestamps
      in directory listings (such as the LastWriteTime column) are rendered
      as relative values, for example just now, 5 min ago, 19 hours ago,
      or 6 days ago. Values older than 7 days, or in the future, are rendered
      using the culture-aware short date and time format.
    • Timespan - A boolean, defaults to $false. Reserved for future use;
      currently has no effect.

    The following example restores the raw byte count display of PowerShell
    7.7 and earlier:

    $PSStyle.HumanReadable.Size = $false
    

Note for the OUTPUT section of Get-ChildItem:

[!NOTE]
Beginning in PowerShell 7.8, file sizes in the default directory listing
are displayed in a human-readable format (for example 1.1 TB). To display
the raw byte count, set $PSStyle.HumanReadable.Size to $false. For more
information, see about_ANSI_Terminals.

Related Source Pull Requests
Related Source Issues
Vorherrschende Sprache
PowerShell
Sterne
2.6k
Forks
1.7k
Ø Merge
3 Std. 49 Min.
Gemergte PRs (30 T.)
5

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus MicrosoftDocs/PowerShell-Docs

Alle Issues in MicrosoftDocs/PowerShell-Docs

Ähnliche Issues

Weitere Issues zu Documentation

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.