2015年10月8日

Powershell command 列出某目錄下 各目錄大小

http://winteltools.com/directory-size/

------------------------------------------


ls | add-member -force -PassThru -name length -type scriptproperty -value { ls $this -Recurse -force | Measure-Object length -Sum | select -ExpandProperty sum }
Description: LS is a power shell command to list directory, A member length is added in conjunction with LS command to display the size of directory after calculating through measure command. Force parameter added after $this to check hidden file as well.
directory size

Command line to list current directory size and sort in descending order.
ls | add-member -force -PassThru -name length -type scriptproperty -value { ls $this -Recurse -Force | Measure-Object length -Sum | select -ExpandProperty sum } | Sort-Object length -Descending
directory size sort

Command line to list top 5 folders name occupying high space as compare to other folders in current directory, this can be change to list top 10 directory by just modifying from -first 5 to -first 10
ls | add-member -force -PassThru -name length -type scriptproperty -value { ls $this -Recurse -force | Measure-Object length -Sum | select -ExpandProperty sum } | Sort-Object length -Descending | select -First 5
directory size first 5

Command line to list current directory size and format the expression to display the size in GB.
ls | add-member -force -PassThru -name length -type scriptproperty -value { ls $this -Recurse -force | Measure-Object length -Sum | select -ExpandProperty sum } | Sort-Object length -Descending | Format-Table Name, @{label=“length”; expression={$_.length/1GB}; f=“{0:N2}”} -autosize
directory size sort format

沒有留言:

張貼留言