Advertisement
Combreal

subDirSize.ps1

Jul 8th, 2020
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Inspired from ERIC COBB's script
  2. $ErrorActionPreference= 'silentlycontinue'
  3.  
  4. $disk = Get-PSDrive S
  5. "Disk size : " + "{0:N2}" -f ($disk.Used / 1GB) + " GB" + "  --  Free space : " + "{0:N2}" -f ($disk.Free / 1GB) + " GB"
  6.  
  7.  
  8. $startDirectory = 'S:\'
  9.  
  10. $directoryItems = Get-ChildItem $startDirectory | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
  11.  
  12. foreach ($i in $directoryItems)
  13. {
  14.     $subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
  15.     if ( $subFolderItems.sum / 1GB -gt 0.01)
  16.     {
  17.         $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB"
  18.     }
  19.     else
  20.     {
  21.         $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement