PoshBytes: How Big Is My File, Really?

PoshBytes: How Big Is My File, Really?

This episode of PoshBytes explains binary sizing in PowerShell and how numeric multipliers like MB and GB make everything clearer.

This post is a companion for the video embedded below. Scroll down to see the code from the video.

Intro

Get the file and inspect its raw size in bytes

$file = Get-Item .\bigfile.iso
$file | Select-Object Name, Length

Convert bytes to megabytes

$file.Length / 1MB

$file.Length / 1KB
$file.Length / 1MB
$file.Length / 1GB
$file.Length / 1TB
$file.Length / 1PB

Filtering using numeric multipliers

Get-ChildItem .\ 

Filtering using numeric multipliers

Get-ChildItem .\ | Where-Object Length -ge 100MB

Filtering using numeric multipliers

Get-ChildItem .\ | Where-Object Length -ge 100MB  | Select-Object Name, @{Name='SizeMB'Expression={"{0:N2} MB" -f ($_.Length / 1MB)}}

Wrap Up

• The Length property shows file size in bytes
• PowerShell uses binary units based on 1024
• 1MB is not 1000000 bytes
• Numeric multipliers like MB and GB are built in
• Using them makes scripts cleaner and more accurate

Leave a Reply

Your email address will not be published. Required fields are marked *