locked
Finding per-user disk usage using powershell RRS feed

  • Question

  • Hi All,

    I have to find the disk utilization as per user using powershell.

    I can do this with UI like -:

    1) Right Click on This PC.

    2) Go to properties from drop down and go to advanced settings

    3) Click on User profile's setting then we can see the users and there usage.

    Now I want to do this programmatically.

    I've requirement like if a particular user usage is more than 2GB space then he should get automatic email trigger.

    How can we do this with powershell?

    Regards,

    Punjab1018

    Tuesday, October 13, 2020 12:36 PM

All replies

  • Hi,

    first, what you're seeing in the GUI is not 'usage per user on disk' but 'size of user profile'. There may be other locations where a user is allowed to write.

    Second, it is not Steady State-related. There used to be several scripting forums, my understanding is that they are being transitioned to Q&A: https://docs.microsoft.com/en-us/answers/topics/windows-server-powershell.html

    Third, here's to get you started:

    foreach ($UserFolder in (Get-ChildItem 'C:\Users')) {
        $SizeBytes = (Get-ChildItem $UserFolder.FullName -Recurse | Measure-Object -Property Length -Sum).Sum
        $SizeGigabytes =  $sizeBytes / 1GB
        Write-Host "$($UserFolder.Name): $SizeGigabytes"
    }
    There are more efficient ways of doing this, though.


    Evgenij Smirnov

    http://evgenij.smirnov.de

    Tuesday, October 13, 2020 6:17 PM