Delete user profile from command line Windows 7

3

Frequently I need to delete all of the user profiles on a computer except for two accounts. I would like to have a script that can perform this for me.

The script must work for Windows 7.

Company policy makes it difficult to download and use any third party utility, so downloading a tool that can accomplish the task is not an acceptable alternative.

Currently I have a vbscript that performs other related functions so if I could do it in VBscript that would be great. If there is a way to do it straight from the Windows command line, that works too I can just call that from my VB script.

I've looked online and I cannot find a way to do this with either VBscript or with a microsoft cmdline utility that comes installed by default on Windows 7.

Does anyone know how I could perform this?

StaticMethod

Posted 2013-09-10T16:11:46.390

Reputation: 167

Dunno man, I googled "VBScript delete profile" and got plenty of info. For example: Delete Profiles Script v1.9, script to delete user profiles and data, Delete Windows profiles (DeleteProfiles2K8.vbs), etc.

– Ƭᴇcʜιᴇ007 – 2013-09-10T16:33:50.077

@techie007 Check out Meta. Just because you can Google it doesn't mean it's a bad question or shouldn't be answered. Stack Exchange is to compile all those answers to show up on Google. So answer the question and not just say Google it. – defaultNINJA – 2013-09-10T17:01:13.963

@defaultNINJA - I've been a member for almost 4 years, I've been to Meta. ;) anyway, I didn't say "google it", nor did I suggest the question should be closed or not answered. I pointed out that contrary to what the user suggests ("I've looked online and I cannot find a way to do this"), there's tons of info to be found on this subject with basic searching, which I provided for his own study. I would have voted to close it if I thought it wasn't supposed to be here. :) – Ƭᴇcʜιᴇ007 – 2013-09-10T17:09:32.740

Answers

4

You can use WMIC.

wmic /node:localhost path win32_UserProfile where LocalPath="c:\\users\\user" Delete 2>>c:\windows\temp\wmic.err

Just replace localhost with the computer name and replace the "user" and the end of the local path with the domain username. It will not remove the domain profile, just the local profile data. It will attempt to remove the whole profile folder after removing the account but sometimes it will be left behind, usually empty.

user318485

Posted 2013-09-10T16:11:46.390

Reputation:

1

You can use the net command for this.

For del user account.

net user YourUsername /del

For Add.

net user YourUserName YourPassword /add

For more info, read How to Use the Net User Command.


There is a command-line tool to do this, call Delprof2(inofficial successor to Microsoft’s Delprof).

Usage: delprof2 [/l] [/u] [/q] [/p] [/r] [/c:[\\]<computername>] [/d:<days> [/ntuserini]] [/ed:<pattern>] [/id:<pattern>] [/i]

   /l   List only, do not delete (what-if mode)
   /u   Unattended (no confirmation)
   /q   Quiet (no output and no confirmation)
   /p   Prompt for confirmation before deleting each profile
   /r   Delete local caches of roaming profiles only, not local profiles
   /c   Delete on remote computer instead of local machine
   /d   Delete only profiles not used in x days
   /ntuserini
        When determining profile age for /d, use the file NTUSER.INI
        instead of NTUSER.DAT for age calculation
   /ed  Exclude profile directories whose name matches this pattern
        Wildcard characters * and ? can be used in the pattern
        May be used more than once and can be combined with /id
   /id  Include only profile directories whose name matches this pattern
        Wildcard characters * and ? can be used in the pattern
        May be used more than once and can be combined with /ed
   /i   Ignore errors, continue deleting

Example of Delprof2 in action, deleting user profiles remotely.

delprof2.exe -c:192.168.175.129 -p 

enter image description here

stderr

Posted 2013-09-10T16:11:46.390

Reputation: 9 300

1It works for local accounts but I'm trying to delete profile data stored on the computer from accounts that belong to a domain. – StaticMethod – 2013-09-10T16:29:23.597

@StaticMethod This does not work? net user YourUsername /del /domain. – stderr – 2013-09-10T16:50:13.847

4net user YourUsername /del /domain deletes the account out of the domain controller which is not what I want. I just want to delete the profile data off of the local computer. delprof2.exe is a third party utility. Company policy makes it difficult for me to use any third party utility. – StaticMethod – 2013-09-10T17:02:42.093

0

Win 7 built in Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> User Profile enable delete profiles after a certain time 60 days 30 days etc.

Will

Posted 2013-09-10T16:11:46.390

Reputation: 1