Forum Discussion

taichroth_84's avatar
taichroth_84
Copper Contributor
Dec 04, 2020

Delete local User Profiles bulk

Dear all,

i search for a script to delete all local user profiles (except system users like admin) as bulk.

we have problems of hard disk space because user profiles are getting bigger and bigger because of cloud use and modern apps.

So please if you have a solution for windows10 enterprise to delete the folder c:\users\xyz and to clean out the registry profile list it would be perfect. all scripts that i have found didn't work.

Thanks for your help. 

3 Replies

  • gastone's avatar
    gastone
    Brass Contributor

    taichroth_84Powershell should be used for this activity, read the following link

    https://powershell.org/forums/topic/delete-user-profiles-except-stafflocal-accounts/

    https://gallery.technet.microsoft.com/scriptcenter/How-to-delete-user-d86ffd3c

     

    • trahojen's avatar
      trahojen
      Copper Contributor

      gastone As of July 7th 2022, both links you provided are broken. There's nothing wrong with referencing links, but if you also provide context, pointers to specific functions, calls or headers involved, your response survives changes elsewhere on the Internet and people can form an educated opinion. Now, as it stands, you have not actually answered the question, and that's a shame, because originally you made an effort to be helpful. Peace brother!

       

      As for the original question, enumerate win32_userprofile with Get-CimInstance, identify the ones you want to delete, and call Remove-CimInstance on them. Adam has written an excellent article on this: https://adamtheautomator.com/powershell-delete-user-profile/

      • gastone's avatar
        gastone
        Brass Contributor
        The shame is that Microsoft when change his websites has lost many useful links (Blog articles, technet gallery et al), I hope in July 7th 2024 to found Adam's link.

Resources