0% found this document useful (0 votes)
5 views1 page

Drive Folder Size Report Script

The script generates a report of all folders on file system drives, including the number of files and their total size in megabytes. It creates a directory for reports if it doesn't exist and exports the results to a CSV file. The report is saved at 'C:\Reports\DriveFolderReport.csv'.

Uploaded by

daggula jcreddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Drive Folder Size Report Script

The script generates a report of all folders on file system drives, including the number of files and their total size in megabytes. It creates a directory for reports if it doesn't exist and exports the results to a CSV file. The report is saved at 'C:\Reports\DriveFolderReport.csv'.

Uploaded by

daggula jcreddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

$OutputFile = "C:\Reports\DriveFolderReport.

csv"

if (!(Test-Path "C:\Reports")) {
New-Item -ItemType Directory -Path "C:\Reports" | Out-Null
}

$Results = @()

$Drives = Get-PSDrive -PSProvider FileSystem

foreach ($Drive in $Drives) {

Write-Host "Scanning Drive:" $[Link]

Get-ChildItem "$($[Link])" -Directory -ErrorAction SilentlyContinue |


ForEach-Object {

try {
$Files = Get-ChildItem $_.FullName -Recurse -File -ErrorAction
SilentlyContinue

$Results += [PSCustomObject]@{
Drive = $[Link]
FolderPath = $_.FullName
FileCount = $[Link]
Size_MB = [Math]::Round(($Files | Measure-Object Length -
Sum).Sum / 1MB, 2)
}
}
catch {}
}
}

$Results | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8

Write-Host "Report generated at:" $OutputFile

You might also like