Multiple user profile delete from user account and regedit

Kabilesh S 1 Reputation point
2022-12-16T13:05:23.697+00:00

I am able to delete single user profile below mentioned script

but i need multiple user profile delete. i tried but not able to find correct cmd

Kindly help me for this. Please help me

set "LocalAccount=MyUser"

for /f "tokens=*" %%i in ('"wmic useraccount where name=^'%LocalAccount%^' get sid | findstr S-1-5"') do set SidValue=%%i

net user %LocalAccount% /del
del C:\Users\%LocalAccount% /F /S /Q
rd C:\Users\%LocalAccount% /S /Q
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%SidValue%" /f

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,822 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,671 Reputation points
    2022-12-19T09:37:30.15+00:00

    Hello there,

    You can use Powershell to achieve your requirement.

    Get-WMIObject -class Win32_UserProfile | Where {(!$.Special) -and ($.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-5))} | Remove-WmiObject

    This will then cause the user profile folder to be deleted, and the corresponding profile list entry in the registry to be removed.

    The below registry also does the same job.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

    Delete the ProfileList key, then all user profiles will be removed completely.

    This can be done rather easily by GPO

    Group Policy: How to Automatically Delete User Profiles Older Than Certain Number of Days https://social.technet.microsoft.com/wiki/contents/articles/28647.group-policy-how-to-automatically-delete-user-profiles-older-than-certain-number-of-days.aspx

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.