Last active
October 5, 2016 13:02
-
-
Save markwragg/694cb79513c947a9a1cab0faf3ddf04f to your computer and use it in GitHub Desktop.
Powershell script to get the total size of a list of folders and the last modified date of the newest file in each folder. The script takes a CSV input file which needs to be a list of paths with a header of "path".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
$Paths = (Import-CSV "Paths.csv") | |
) | |
$i = 0 | |
$Total = 0 | |
$Paths | ForEach-Object { | |
Write-Progress -Activity "Getting folder size for $($_.Path)" -PercentComplete (($i / $Paths.Count) *100) -Status ("Total size -- " + "{0:N2}" -f $Total + "MB") | |
$subFolderItems = (Get-ChildItem $_.path -Recurse) | |
$FolderSize = ($subFolderItems | Measure-Object -property length -sum | Select Sum -ExpandProperty Sum) / 1MB | |
$NewestFile = $subFolderItems | sort LastWriteTime | select -last 1 | |
$Result = @{ | |
Path = $_.path | |
SizeMB = $FolderSize | |
LastWritten = $NewestFile.LastWriteTime | |
} | |
New-Object PSObject -Property $Result | |
Write-Verbose ("$($_.path) -- " + "{0:N2}" -f $FolderSize + "MB") | |
$Total += $FolderSize | |
$i++ | |
} | Export-CSV "Paths-Sizes.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment