Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- This script display space left on disk and list all subdirectory of current directory and show the size of each of them.
- Inspired from ERIC COBB's script
- #>
- $ErrorActionPreference = 'silentlycontinue'
- function LSDS {
- $disk = (Get-Location).Drive
- "Disk size : " + "{0:N2}" -f ($disk.Used / 1GB) + " GB" + " -- Free space : " + "{0:N2}" -f ($disk.Free / 1GB) + " GB"
- $startDirectory = Get-Location
- $directoryItems = Get-ChildItem $startDirectory | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
- foreach ($i in $directoryItems)
- {
- $subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
- if ( $subFolderItems.sum / 1GB -gt 0.01)
- {
- $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB"
- }
- else
- {
- $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"
- }
- }
- }
- Export-ModuleMember -Function LSDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement