Get FIle Size using PowerShell

We can make use of the Get-Item cmdlet from the Microsoft.PowerShell.Management module to get the size of a file.

Let's take a look at a few one-liner examples.

Example 1: For a File

    (Get-Item 'data_2023.csv').Length


Example 2: For a File with Absolute Path

    (Get-Item 'D:\documents\annual_report.xlsx').Length


Example 3: Convert File Size from Bytes to KB/MB

    "{0:N2} {1}" -f ((Get-Item 'sharepoint.png').Length / 1MB), "MB"

    0.02 MB

Get the Size of File using PowerShell

Example demonstrated on macOS with Powershell version 7.2

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap