2

I'm very new to powershell and is it possible to obtain the actual size of disk of a file? I was able to use the du, but is there another way of doing this without using that application?

Xander Vane
  • 197
  • 2
  • 4
  • 20
  • _actual size of disk of a file_ does not make sense to me. Are you looking for file size or disk size. One is Get-Item and the other could be a WMI query. Either of which are easily searched even here. Perhaps you mean size __on__ disk? – Matt Sep 09 '15 at 03:07
  • Possible duplicate of http://stackoverflow.com/questions/554010/how-to-get-the-actual-size-on-disk-of-a-file-from-powershell – Matt Sep 09 '15 at 03:08
  • 1
    Yes I mean the "size on disk" which could be seen when you right click a folder or file, Get-Item doesnt seem to show it – Xander Vane Sep 09 '15 at 17:24

1 Answers1

-1

This will give you the actual size of a file in bytes:

(gci <insert file path> | Measure-Object -Property length -Sum).sum

You can then use other logic to convert to KB, MB, GB, whatever you want. You can use the same command for size of directories, with the -Recurse option to get the size of all subdirectories and files in the root.

Ash Housewares
  • 155
  • 1
  • 8