Today I was notified that my home drive was using more than 5GB of data and must be reduced below 5GB immediately. Ignoring the wisdom of having employees delete the product of their labour in an era of cheap storage, no method of finding out what was using the space within my drive was suggested or seemingly available on my work laptop, so I wrote a short PowerShell script to work it out:

$folder_list = Get-ChildItem -Directory
foreach($folder in $folder_list) {
    $size = Get-ChildItem -Path $folder.FullName -Recurse | Measure-Object -Sum Length
    $pretty_size = switch($size.Sum) {
        {$_ -gt 1GB} {
            '{0:0.0} GiB' -f ($_/1GB)
            break
        }
        {$_ -gt 1GB} {
            '{0:0.0} MiB' -f ($_/1MB)
            break
        }
        {$_ -gt 1GB} {
            '{0:0.0} KiB' -f ($_/1KB)
            break
        }
        default { "$_ bytes" }
    }
    Write-Host folder.FullName "    File Count:" $size.Count  "    Size:" $pretty_size
}

Initially, I received an error File foldersizes.ps1 cannot be loaded because running scripts is disabled on this system. (foldersizes.ps1 is what I had saved the above script as). To get around this, I changed the execution policy to Unrestricted:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

Afterwards, I set it back to the default of Undefined:

Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser

To see the execution policies for each scope, this command can be used:

Get-ExecutionPolicy -List