0

Im sure there are other ways to do this, but im trying to learn and trying to see how I can convert this length output to GB format

dir $env:USERPROFILE -Recurse -File | sort-object -property length | select -last 10

Thanks alot!

Romeo Ninov
  • 5,319
  • 5
  • 20
  • 20
Matt
  • 3
  • 2
  • Does [Show human-readable file sizes in the default PowerShell ls command](https://superuser.com/questions/468782/show-human-readable-file-sizes-in-the-default-powershell-ls-command) help? – Andrew Morton Jul 10 '22 at 14:46
  • 1
    I tried that but was more looking for the below, thanks – Matt Jul 10 '22 at 16:05

1 Answers1

0

Unfortunately there is no easy -h like in Linux. You could do it like this:

select *,@{n='Length (GB)';e={$_.Length / 1GB}} -exclude length -last 10

Basically you select every property (*) add a calculated property to the output @{n='Length (GB)';e={$_.Length / 1GB}} and exclude the normal length (optional)

SimonS
  • 8,924
  • 5
  • 28
  • 48
  • Thanks SimonS, that did it. I will now try and wrap my head around how exactly that works! – Matt Jul 10 '22 at 15:33
  • Im trying to see if there is a way to use math::[round] or something to only have 2 decimal places? or may {0:F2}? – Matt Jul 10 '22 at 17:23
  • @Matt yes, like this `e={"{0:N2}" -f ($_.Length / 1GB)}}`, -f is the format operator – SimonS Jul 11 '22 at 06:30