• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
ControlUp Community

ControlUp Community

Connect, Learn, and Grow

  • Blog
  • Podcast
  • Meetups
  • Archives
  • Categories
    • ControlUp One Platform
    • ControlUp for Apps
    • ControlUp for Compliance
    • ControlUp for Desktops
    • ControlUp Scripts & Triggers
    • ControlUp Synthetic Monitoring
    • ControlUp for VDI
  • Topics
  • Events
    • Logos & Wallpaper
    • ControlUp.com
  • Join

Getting Detailed Folder Sizes on VDI using ControlUp

Posted on May 9, 2024

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
Topics: ControlUp Monitor, Reporting, Scripts, VDI

Ask Us Anything, Connect, Learn, and Grow with the ControlUp Community!

Login to the ControlUp Community to ask us anything, stay up-to-date on what’s new and coming soon and meet other like-minded techies like you.

Not already a member? Join Today!

Primary Sidebar

ControlUp Academy

Enroll in ControlUp Academy for expert-led technical training, equipping you with skills to effectively deploy, manage, and grow your ControlUp investment.

Learn here >

Rotating Images

Hidden Gem from our Community on Slack!

ControlUp Betas - What's Coming Next?
NEW ControlUp Features - Stay Up-to-Date!
ControlUp Scripts - Scripting, Zero to Hero
Latest KB Articles - Be the First to Learn
Did you Know - with Sivan Kroitoru
Practical Perspectives Technical Use Case Training

Video Tutorials Library

Visit our technical how-to videos, offering step-by-step tutorials on advanced features, troubleshooting, and best practices.

Watch here >

ControlUp Blog

Check out the ControlUp blog for expert advice and in-depth analysis.

Read here >

ControlUp Script Library

Visit the ControlUp technical script library, which offers a multitude of pre-built scripts and custom actions for your monitoring and troubleshooting requirements.

See here >

ControlUp Support

Visit the ControlUp support home and to delve deeper into ControlUp solutions.

Browse here >

Download ControlUp RealTime DX

Start with ControlUp for real-time end-user environment insights, swift troubleshooting, and unprecedented performance optimization. Download now.

Download here >

Footer

      

ControlUp Community
Of Techie, By Techie, For Techie!

Terms of Use | Privacy Policy | Security
Dive Deeper, Learn more at ControlUp.com

  • facebook
  • twitter
  • youtube
  • linkedin

© 2023–2025 ControlUp Technologies LTD, All Rights Reserved.

We use cookies to ensure that we give you the best experience on our website. by continuing to use this site you agree to our Cookie policy..