script to delete users profile

Page 1 of 2 12 LastLast

  1. Posts : 5
    Windows 10 Pro
       #1

    script to delete users profile


    hello guys, I'm new here. can someone help me please
    I need a script with following conditions:
    1- run on windows start up.
    2- check the users profile if not logon more than 30 days on this PC, then delete that profile. (not include the administrator profile).
      My Computer


  2. Posts : 869
    Windows 10 Professional x64 21H2
       #2

    Welcome to TenForms v444. We have some very good batch writers here, but it would help them to know why you need this sort of batch written. Please give us more detail as to why you need this done. I'm very sure that they'll be asking you this.
      My Computers


  3. Posts : 5
    Windows 10 Pro
    Thread Starter
       #3

    Lance1 said:
    Welcome to TenForms v444. We have some very good batch writers here, but it would help them to know why you need this sort of batch written. Please give us more detail as to why you need this done. I'm very sure that they'll be asking you this.
    im doing design classes on my PC, so i have too many students and creating a separate user for each one, then i need to delete their user manually. so i think to have a batch to automate that job is smarter way.
      My Computer


  4. Posts : 1,776
    Windows 10 Pro (+ Windows 10 Home VMs for testing)
       #4

    A few more questions that may be asked...

    1. Are these domain user profiles on the PC or local users?
    2. Do you need logging of success/failure/names of deleted profiles, etc. and, if so, seperate logs or a combined one?
    3. What filepath to use for any log(s)?
      My Computer


  5. Posts : 5
    Windows 10 Pro
    Thread Starter
       #5

    RickC said:
    A few more questions that may be asked...

    1. Are these domain user profiles on the PC or local users?
    2. Do you need logging of success/failure/names of deleted profiles, etc. and, if so, seperate logs or a combined one?
    3. What filepath to use for any log(s)?
    A1- i guess local. (please check the attachment,i'm following those steps to do it, if it helps you to figure out if it's on PC or local)
    A2- no i don't need logs.

    Full user delete.docx
      My Computer


  6. Posts : 1,776
    Windows 10 Pro (+ Windows 10 Home VMs for testing)
       #6

    My apologies, I wasn't clear.

    Is this PC attached to a domain (i.e. where user accounts of students are created elsewhere and local roaming profiles are created on whatever domain-attached devices they log on to)?

    I get the impression that it's either a standalone PC or in a peer-to-peer workgroup using just local accounts. If so then it's more complicated than just automating the process of deleting local profiles older than 30 days from a scheduled task run at startup.

    The doc you attached shows a manual method of deleting profiles using a local account with administrative privileges, i.e. an account in the local Administrators group. What mechanism would you use to create a new local account for a user if their old profile was deleted and they then needed to use the PC again?

    Libraries tend to avoid all this complexity of having to create individual user accounts on shared PCs by using third-party products like Faronics' Deep Freeze where there's a single 'standard' user account on each PC which is refreshed from a hidden image on startup. Unfortunately Deep Freeze has become quite expensive. Microsoft used to have a freeware equivalent called Windows SteadyState but it's never been available for Windows 10. There are, however, alternatives to Deep Freeze.

    Sorry for all the questions. Automatically deleting profiles is fairly easy. For example, from PowerShell:

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

    Automatically creating new profiles is not...

    (EDIT: Or see this TechNet article: How to delete user profiles older than a specified number of days in Windows for another PowerShell method... which still doesn't address the issue of automatic creation of new profiles.)

    Hope this helps...
      My Computer


  7. Posts : 1,776
    Windows 10 Pro (+ Windows 10 Home VMs for testing)
       #7

    Many years ago I used to support young people who had been provided with Toshiba laptops for their education. The laptops were all identical so I was able to use a disk image to provision all of them. Once in the hands of young people there were inevitable issues with viruses and, basically, just 'breaking by fiddling'.

    I came up with a method to let their parents 'fix' the laptops by booting from a USB stick (which we also provided). The 'FixStix' contained a copy of Symantec's Ghost (it was quite a few years ago) and a batch file that told Ghost to re-image the system partition from an image stored in another partition. The process took about 5 minutes from USB boot to startup of a 'fixed' system.

    Would this method be something worth pursuing?
      My Computer


  8. Posts : 5
    Windows 10 Pro
    Thread Starter
       #8

    RickC said:
    My apologies, I wasn't clear.

    Is this PC attached to a domain (i.e. where user accounts of students are created elsewhere and local roaming profiles are created on whatever domain-attached devices they log on to)?

    I get the impression that it's either a standalone PC or in a peer-to-peer workgroup using just local accounts. If so then it's more complicated than just automating the process of deleting local profiles older than 30 days from a scheduled task run at startup.

    The doc you attached shows a manual method of deleting profiles using a local account with administrative privileges, i.e. an account in the local Administrators group. What mechanism would you use to create a new local account for a user if their old profile was deleted and they then needed to use the PC again?

    Libraries tend to avoid all this complexity of having to create individual user accounts on shared PCs by using third-party products like Faronics' Deep Freeze where there's a single 'standard' user account on each PC which is refreshed from a hidden image on startup. Unfortunately Deep Freeze has become quite expensive. Microsoft used to have a freeware equivalent called Windows SteadyState but it's never been available for Windows 10. There are, however, alternatives to Deep Freeze.

    Sorry for all the questions. Automatically deleting profiles is fairly easy. For example, from PowerShell:

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

    Automatically creating new profiles is not...

    (EDIT: Or see this TechNet article: How to delete user profiles older than a specified number of days in Windows for another PowerShell method... which still doesn't address the issue of automatic creation of new profiles.)

    Hope this helps...
    The PC is connected to a domain, when new user want to use the PC he just log in using (Ctrl+Alt+Del) his username and password, so the profile created in that PC, after he end his course (30 days period) i'm following the steps in the document to remove his profile from that PC.

    - - - Updated - - -

    RickC said:
    Many years ago I used to support young people who had been provided with Toshiba laptops for their education. The laptops were all identical so I was able to use a disk image to provision all of them. Once in the hands of young people there were inevitable issues with viruses and, basically, just 'breaking by fiddling'.

    I came up with a method to let their parents 'fix' the laptops by booting from a USB stick (which we also provided). The 'FixStix' contained a copy of Symantec's Ghost (it was quite a few years ago) and a batch file that told Ghost to re-image the system partition from an image stored in another partition. The process took about 5 minutes from USB boot to startup of a 'fixed' system.

    Would this method be something worth pursuing?
    i have similar USB for recovering windows image with Acronis including all software needed for students.
      My Computer


  9. Posts : 1,776
    Windows 10 Pro (+ Windows 10 Home VMs for testing)
       #9

    v444 said:
    The PC is connected to a domain, when new user want to use the PC he just log in using (Ctrl+Alt+Del) his username and password, so the profile created in that PC, after he end his course (30 days period) i'm following the steps in the document to remove his profile from that PC.
    My apologies again. You're a tutor yet are also doing basic IT maintenance tasks?

    If a domain administrator takes care of student account creation, why doesn't he/she also do the profile cleanups (and software provisioning)? It's a standard (and usually automated) admin task using the domain administrator account to take care of processes that require elevated privileges and/or manage PowerShell execution policies.

    Do you have a local admin account? If so - and assuming local PowerShell execution policy allows it - why not run a PowerShell script from an elevated console 'as required' instead of the hassle of setting up a scheduled task?

    For example, say you had a local admin account (and your account username was v444) then the TechNet script I linked to above could be used as follows:

    Code:
    C:\Script\RemoveLocalUserProfile.ps1 -DeleteUnusedDay 30 -ExcludedUsers “v444”

    ... or from wherever you stored the RemoveLocalUserProfile.ps1 script (e.g. your USB device used for provisioning software).

    Hope this helps...
      My Computer


  10. Posts : 5
    Windows 10 Pro
    Thread Starter
       #10

    RickC said:
    My apologies again. You're a tutor yet are also doing basic IT maintenance tasks?

    If a domain administrator takes care of student account creation, why doesn't he/she also do the profile cleanups and software provisioning? It's a standard (and usually automated) admin task using the domain administrator account to take care of processes that require elevated privileges and/or PowerShell execution policies.

    Do you have a local admin account? If so - and assuming local PowerShell execution policy allows it) why not run a PowerShell script from an elevated console 'as required' instead of the hassle of setting up a scheduled task?

    For example, say you had a local admin account (and your account username was v444) then the TechNet script I linked to above could be used as follows:

    Code:
    C:\Script\RemoveLocalUserProfile.ps1 -DeleteUnusedDay 30 -ExcludedUsers “v444”

    ... or from wherever you stored the RemoveLocalUserProfile.ps1 script (e.g. your USB device used for provisioning software).

    Hope this helps...
    yeah a tutor and doing basic IT maintenance tasks, if you have a lazy system administrator you need to do everything by your own. but yes this last one helps, thank you so much.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:01.
Find Us




Windows 10 Forums