jdhitsolutions / PSScriptTools

:wrench: :hammer: A set of PowerShell functions you might use to enhance your own functions and scripts or to facilitate working in the console. Most should work in both Windows PowerShell and PowerShell 7, even cross-platform. Any operating system limitations should be handled on a per command basis. The Samples folder contains demonstration script files
MIT License
872 stars 108 forks source link

[Bug]: get-foldersize and user profile files #145

Open jszabo98 opened 4 months ago

jszabo98 commented 4 months ago

Describe the problem

get-foldersize doesn't seem to return the correct size for user profiles, maybe because of things like symlinks? It is fast though.

Expectation

No response

Additional Information

No response

PowerShell version

4.0

Platform

None

Additional Checks

jdhitsolutions commented 4 months ago

What version of PowerShell are you using? What path are you querying? Are you including hidden files?

jszabo98 commented 4 months ago

Powershell 5.1. c:\users. Including hidden files.

jdhitsolutions commented 4 months ago

You'll probably get access-denied messages for parts of that path, even if running as Admin. I did a test on my profile in Windows PowerShell.

Get-FolderSizeInfo $home -hidden

My total size is actually about 3GB more than what I get when I use Windows Explorer and look at properties. The same test in PowerShell 7 is closer to the results I see in Windows Explorer. This is on a Windows 11 system. Profile folders are tricky due to hidden files and special access permissions.

Although, there might be an issue with symlinks. In Windows PowerShell, the function follows the link and includes the size information, but not in PowerShell 7, which uses a different .NET method.

jszabo98 commented 4 months ago

This suits me, to skip the reparsepoints like the mounted Onedrive ...

$top = ($di.GetDirectories()).Where( { $_.attributes -notmatch 'reparsepoint' })

jdhitsolutions commented 4 months ago

Let me see what I can come up with.

jdhitsolutions commented 1 month ago

I have a new version for the next release. I am now skipping all reparse points and junctions.

jdhitsolutions commented 1 month ago

v2.49.0 has been published to the PowerShell Gallery if you want to update and test.

jszabo98 commented 3 weeks ago

Looks good. Actually my typical usage is like this, sort of "du | sort -n". It's good for avd, where the disk is slower.

icm comp001 { dir -dir -force C:\programdata\ | Get-FolderSizeInfo.ps1 | sort totalsize } | ft -a