gareth asked this 4 years ago

Powershell to get a file's size on disk

I want to write a powershell script that gives the actual size on disk of a list of files. i know (Get-Item filename).length will give you the size. But this is the size of the file and not the actual space it takes on the disk.


Best Answer by Fischer 3 years ago

You can do this using the Net Platform Invoke (P/Invoke) feature and call the Win32 function GetCompressedFileSizeW to get the actual size of the file.

Check this article: Powershell to get actual size on disk of a file