Completely Delete User Profiles with a Script

You may also like...

23 Responses

  1. Matt says:

    I get the following error (in the .txt file)when running the script:

    “Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.

    Input Error: There is no script engine for file extension “.vbs WM-ROSWELL”.

    Where “WM-ROSWELL” is the name of the server.

  2. Nik says:

    Hi Matt,

    you’re trying to run the following command right.

    cscript.exe nameofthevbs.vbs WM-ROSWELL

    Have you changed the script part where you have to enter the domain name?

  3. Matt says:

    Yes, but I used the NetBIOS name rather than the FQDN.

    Does this need to be run on the local server, or can I do this from my workstation?

    Thanks for the help!

  4. Nik says:

    You can do this from your workstation too.
    Is it working for you now Matt?

  5. Matt says:

    No it is not. I can email you the files (.vbs and .bat) I am using if you would like…

  6. Nik says:

    Please upload your file somewhere and post a link here.
    I will check it out..

  7. Nik says:

    Check if you have admin permissions on the target machine.

    Make sure to run script like this:

    Cscript.exe delete_profiles.vbs TARGETMACHINE > deleted.txt

    Also, run CMD in elevated mode if you have UAC turned on.

  8. Matt says:

    Where do I set those permissions?

    Do I just make a local admin account that matches my domain account name?

  9. Nik says:

    Your domain account has to be local administrator on the target machine.
    I’ve tried the script and the script successfully deleted all of the profiles that currently were not in use on the target machine.

  10. Matt says:

    I got it to work! I needed to take the quotes out of the .bat file…duh moment. I am by no means a script guru. It successfully worked on two terminal servers!

    Thanks again!

  11. Josh says:

    How do I do this for multiple usernames I want to ignore?

    And additionally is it easy to add a function such as (older than 7 days)? now that I’ve found your script classes have started this week and I need to delete all the student accounts older than a week ago.

  12. Adam says:

    I am trying to get this to work but the profiles do not appear to be deleting. In the log file, the output only shows the server name. Any thoughts?

  13. Nik says:

    Hi Adam,
    Script seems fine. Do you have Admin Permission on the target machine?

    Please check that you did everything right.
    You can also attach your script so I can download and check.

  14. Ganesan K says:

    Thanks for sharing nice techie info for ours.. keep posted buddy….

  15. prabhu says:

    I dont know if the author of the code still active. I am getting error message – Microsoft VBScript compilation error line 18 char 66 expected ‘)’ code:800A03EE

    server os:2008 r2

  16. prabhu says:

    Also will it be possible to exclude the Service account and Network accounts along with the Local Administratoe

  17. prabhu says:

    I found the issue actually there is extra single quote and double quote which was causing the issue.
    the script deletes profile from C:\Users which is good. I would like to know will it touches the local administrator account? and if users logged on to the server will it deletes their profile?

    Scripts works fine without any issue on my test server, as i will be using to clear it on Citrix host server I would like to know more information
    Thanks

    • Nik says:

      I’m quite sure it shouldn’t delete profile from the local admin. Also if the user is logged on that profile is locked and thus can’t be deleted.
      BTW, why not running the script during the night to avoid having any issues with already logged users?

  18. prabhu says:

    Hi Nik, Thanks for replying back. Yes, i tested it its not deleting the local Admin and logged in user.Yes, that what I planned it for running the script Out of hours.

    But I work for healthcare so 24/7. Thanks for replying back.

  19. Prabhu says:

    Hi Nik, I tested the script on one of the production server. It execute the script but nothing happen. no error message nothing. Any idea?
    Did the same with the Test server. But on the production it does nothing.

    • Nik says:

      No idea Prabhu, this script was used only for our 2008R2 server environment. Now we’re using Citrix profiler so we don’t have the need to delete local user profiles.

  20. Prabhu Alagurajan says:

    And its weird it works only when the Citrix server is on Maintenance mode

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.