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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap