Skip to content

Add ConvertTo-HumanizedByteSize cmdlet#21

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/add-byte-size-extensions-cmdlet
Open

Add ConvertTo-HumanizedByteSize cmdlet#21
Copilot wants to merge 2 commits intomasterfrom
copilot/add-byte-size-extensions-cmdlet

Conversation

Copy link

Copilot AI commented Dec 31, 2025

Exposes the Humanizer ByteSizeExtensions.Humanize API as a PowerShell cmdlet.

Changes

  • New cmdlet ConvertTo-HumanizedByteSize in PowerShellHumanizer.psm1

    • Accepts byte values via parameter or pipeline
    • Optional -Format parameter for custom number formatting (e.g., #, 0.00)
    • Automatically selects appropriate units (B, KB, MB, GB, TB)
  • Tests added to PowerShellHumanizer.Tests.ps1

    • Basic conversions, decimal values, format parameter, pipeline support
  • Documentation added to README.md with usage examples

Usage

# Basic usage
ConvertTo-HumanizedByteSize 1048576
# 1 MB

# Pipeline support
1024, 2048, 3072 | ConvertTo-HumanizedByteSize
# 1 KB
# 2 KB  
# 3 KB

# Custom formatting
ConvertTo-HumanizedByteSize 1536 -Format '#'
# 2 KB
Original prompt

This section details on the original issue you should resolve

<issue_title>Add [ByteSizeExtensions]::Humanize Cmdlet</issue_title>
<issue_description>Expose this API in a cmdlet.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: dfinke <67258+dfinke@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ByteSizeExtensions::Humanize cmdlet Add ConvertTo-HumanizedByteSize cmdlet Dec 31, 2025
Copilot AI requested a review from dfinke December 31, 2025 17:48
Copy link

@mattcargile mattcargile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest removing that line.

)

Process {
$byteObject = [Humanizer.ByteSizeExtensions]::Bytes($ByteSize)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary if accepting bytes. [ByteSize] has a constructor to auto convert on the Humanize method.

@dfinke dfinke marked this pull request as ready for review January 6, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add [ByteSizeExtensions]::Humanize Cmdlet

3 participants