Run this PowerShell script to list all folders over a specified size. The default script uses 1000 MB as the threshold but you can edit to whatever size is suitable.
###
# Show Large Folders
#
# Description:
# Highlights a list of all folders (not subfolders) in red when the folder is over a threshold size.
##Run in PowerShell ISE with admin rights
#
# Version: 1.0
# Updated: 20231020
# Author: Julian Dalley
###
# Define the drive and threshold size (in MB) for highlighting$drive = "C:\"$thresholdSizeMB = 1000
# Function to format file sizes in a human-readable formatfunction Format-Size { param([double]$size) $units = "B", "KB", "MB", "GB", "TB" $unit = 0 while ($size -ge 1KB -and $unit -lt 4) { $size /= 1KB $unit++ } "{0:N2} {1}" -f $size, $units[$unit]}
# Function to check if the current user has access to a folderfunction Test-FolderPermission { param($folderPath) try { $null = Get-Acl $folderPath return $true } catch { return $false }}
# Function to get folder size, handling "Access is denied" errorsfunction Get-FolderSize { param($folderPath) if (Test-FolderPermission -folderPath $folderPath) { $folderSize = Get-ChildItem $folderPath -File -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum return $folderSize.Sum } else { Write-Host "Access is denied or insufficient permissions for folder: $folderPath" -ForegroundColor "Yellow" return 0 }}
# Get a list of folders and their sizes$folderSizes = Get-ChildItem $drive -Directory | ForEach-Object { $folder = $_ $folderSize = Get-FolderSize -folderPath $folder.FullName [PSCustomObject]@{ Folder = $folder.FullName Size = $folderSize }}
# Highlight folders with size exceeding the threshold$highlightColor = "Red"$normalColor = "White"$folderSizes | Where-Object { $_.Size -ge ($thresholdSizeMB * 1MB) } | ForEach-Object { Write-Host ("Folder: {0} - Size: {1}" -f $_.Folder, (Format-Size $_.Size)) -ForegroundColor $highlightColor}
# List folders below the threshold$folderSizes | Where-Object { $_.Size -lt ($thresholdSizeMB * 1MB) } | ForEach-Object { Write-Host ("Folder: {0} - Size: {1}" -f $_.Folder, (Format-Size $_.Size)) -ForegroundColor $normalColor}
Related Articles
PowerShell script to monitor the process and folders used by the cloud metering process 75Number of Views FlexNet agent (ndtrack) may trigger a security software warning due to PowerShell script execution containing unusual char… 78Number of Views PowerShell script to delete the Snow MongoDB service 6Number of Views PowerShell script to monitor the log files generated and deleted in a folder 11Number of Views PowerShell script to rebuild the Snow MongoDB Windows service 9Number of Views
Hi, I am Reva - Ask me anything.
No new updates
Thanks for the feedback!
Your feedback has been saved.Rate this response:
Add Additional feedback ( Optional )
Are you sure you want to cancel
the case creation?
Are you sure you want to cancel the case creation?
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
Revenera Assistant
Case id: 00001065
Activity: Status change: 2 hours ago