A user asked for a script to get a detailed breakdown of folder sizes on virtual desktop infrastructure (VDI), and a solution was suggested using Get-FolderSize and Format-Size functions. Another user suggested using treesize CLI, which is freeware, but it was noted that the paid version is needed for the CLI. A script was successful in pulling the list of VDI from ControlUp Monitor. Get-cucomputers was also mentioned as a solution.
Read the entire ‘Getting Detailed Folder Sizes on VDI using ControlUp’ thread below:
hi guys i need a script to run on VDIs that gives a very details breakdown of Folder sizes, was trying this one but customer i looking for deeper and more granualar, any one got one that they use?
Function to calculate folder size
function Get-FolderSize {
param (
[string]$folderPath
)
$size = 0
try {
$files = Get-ChildItem $folderPath -File -Recurse -ErrorAction SilentlyContinue
if ($files) {
$size = ($files | Measure-Object -Property Length -Sum).Sum
}
} catch {
Write-Host "Error calculating size for folder: $folderPath"
}
return $size
}
Function to format size into human-readable format
function Format-Size {
param (
[double]$size
)
$units = ("B", "KB", "MB", "GB", "TB")
$unitIndex = 0
while ($size -ge 1KB -and $unitIndex -lt $units.Length) {
$size /= 1KB
$unitIndex++
}
"{0:N2} {1}" -f $size, $units[$unitIndex]
}
Main script
$drive = "C:\"
$outputTextFilePath = "C:\Folder_Size_Report.txt"
$outputCsvFilePath = "C:\Folder_Size_Report.csv"
if (Test-Path $drive -PathType Container) {
$folders = Get-ChildItem $drive -Directory -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
$folderSizes = @()
foreach ($folder in $folders) {
$folderSize = Get-FolderSize $folder
if ($folderSize -ge 1GB) {
$formattedSize = Format-Size $folderSize
$outputMessage = "Total size of $folder is: $formattedSize"
Write-Host $outputMessage
$outputMessage | Out-File -FilePath $outputTextFilePath -Encoding utf8 -Append
$folderSizes += [PSCustomObject]@{
Folder = $folder
Size = $formattedSize
}
}
}
# Sort folder sizes by size in descending order
$sortedFolderSizes = $folderSizes | Sort-Object -Property {[double]$_.Size.Split(" ")[0]} -Descending
# Export sorted folder sizes to CSV
$sortedFolderSizes | Export-Csv -Path $outputCsvFilePath -NoTypeInformation -Append
} else {
Write-Host "Drive path does not exist."
}
pulls back all folders over 1GB in size only thing is it is not accurate on the C: User folder for some reason
Why not use the treesize CLI? https://manuals.jam-software.de/treesize/EN/command_line_opt.html
they will need to pay forthat?
Ohh, I have no idea, just a suggestion…
yeah i said use tree size was told they don’t have it
I haven’t read a EULA but its under freeware.
Ehh… CLI is only in the paid version. 😞
but sript now dowing the job getting all folders over 1 GB and pulling the list of VDI crom CU monitor
get-cucomputers has a -folderpath parameter? I knew that 😇
Continue reading and comment on the thread ‘Getting Detailed Folder Sizes on VDI using ControlUp’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers