Powershell Folder Size Specific Folder Name

Powershell script to loop through a folder looking for specific folder names and reporting back the folder size. Our DIFF backups were stored in a folder under the server name and I needed a way to see the size of all DIFF folders.

$sourceDirectory = "\\path to your folder\folder"
$folderName = "Diff"

$colItems = (Get-ChildItem $sourceDirectory -recurse | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match $folderName} )
foreach ($i in $colItems)
{
    $subFolderItems = (Get-ChildItem $i.FullName | Measure-Object -property length -sum)
    $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB" 
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s