Advertisement
Combreal

LSDS.psm1

Jul 9th, 2020
1,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3. This script display space left on disk and list all subdirectory of current directory and show the size of each of them.
  4. Inspired from  ERIC COBB's script
  5. #>
  6.  
  7. $ErrorActionPreference = 'silentlycontinue'
  8.  
  9. function LSDS {
  10.    
  11.     $disk = (Get-Location).Drive
  12.     "Disk size : " + "{0:N2}" -f ($disk.Used / 1GB) + " GB" + "  --  Free space : " + "{0:N2}" -f ($disk.Free / 1GB) + " GB"
  13.    
  14.     $startDirectory = Get-Location
  15.      
  16.     $directoryItems = Get-ChildItem $startDirectory | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
  17.      
  18.     foreach ($i in $directoryItems)
  19.     {
  20.         $subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
  21.         if ( $subFolderItems.sum / 1GB -gt 0.01)
  22.         {
  23.             $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB"
  24.         }
  25.         else
  26.         {
  27.             $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"
  28.         }
  29.     }
  30. }
  31. Export-ModuleMember -Function LSDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement