xwarsawx74 Posted July 3, 2017 Posted July 3, 2017 (edited) Hello EDU GEEKS! One of the users here had previously recommended the Delprof2 by Halgen Klein to delete local profiles. https://helgeklein.com/free-tools/delprof2-user-profile-deletion-tool/ So, this is my scenario... I work at an Art School where students log in to our computers using their domain accounts. We are currently using HP z440 Workstations running on Windows 10 EDU x64. My goal is to have students accounts (locally created) deleted upon Log-off, Re-start, or Shutdown. I have previously used the Delprof policy but it is not efficient (Roaming Profiles is not an option). I have not used Delprof2, and I am looking for ideas on how to implement this tool to my PC image. This is what I'm looking for.. 1. Have the Delprof2 Tool run as a script (if this is possible) at log-on, log-off, or restart (either works). 2. The Delprof2 Tool will then delete ONLY profiles that begin with the letter "X" (no more than 1 day old). 3. The Delprof2 Tool should NOT delete any other local accounts by the names of "Administrator", "Admin", "default" or "wkstnlocal". 4. When the Delprof2 command runs, It should not prompt me to enter Y or N, it should run unattended. Any ideas would be great! and if I can get instructions on how to implement this as a Log-off or Startup Script that would be magnificent!! Cheers and much thanks in advance!!! Edited July 3, 2017 by xwarsawx74
dapaulio Posted July 3, 2017 Posted July 3, 2017 (edited) Still use delprof here on shutdown script. delprof.exe /q /I /d:2 Q = quiet I = ignore errors and continue D = number of days inactive It also ignores public and default Edited July 3, 2017 by dapaulio
colly72 Posted July 3, 2017 Posted July 3, 2017 Check here: http://www.edugeek.net/forums/windows-7/149642-delprof2-startup-script.html
Oaktech Posted July 4, 2017 Posted July 4, 2017 Or you could use a GPO to create a scheduled task on all workstations - you can set scheduled tasks to be dependent on a lot of different triggers - I quite like on idle so no-one gets impacted while the task runs. Just use delprof2.exe as the program to run from whatever location - we have it on a readonly hidden share, and the parameters as above to specify behaviour. You can set the task to run as whatever user you like - system seems quite popular.
Popular Post Warwick_Tech Posted July 5, 2017 Popular Post Posted July 5, 2017 we dropped Delprof2 when it didn't work consitently for our windows 10 machines, Instead we use a powershell script set to run on shutdown ; $profiles = $null $profiles = Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\UpdatusUser"))} if ($profiles -ne $null) { $profiles | Remove-WmiObject } Exit And it seems to work with corrupt profiles too. 6
Killer_Bot Posted September 26, 2017 Posted September 26, 2017 (edited) Thanks for that Warwick. We're still Windows 7 here but will go the Powershell route too as we soon plan to go into Windows 10. As an aside I've modified the script slightly to only delete profiles that haven't been used in 'x' amount of days (to avoid Staff profiles deleting daily). Wanted to share on here should anyone else want to do something similar. $profiles = $null $profiles = Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ` ($_.LocalPath -ne "C:\Users\Administrator") -and ` ($_.LocalPath -ne "C:\Users\UpdatusUser") -and ` ($_.LocalPath -ne "C:\Users\LocalAccountName") -and ` ($_.LocalPath -ne "C:\Users\Administrator.domain") -and ` ($_.LocalPath -ne "C:\Users\prtg"))} $timespan = new-timespan -days 7 -hours 0 -minutes 0 if ($profiles -ne $null) { foreach ($user in $profiles) { $last_active = [Management.ManagementDateTimeConverter]::ToDateTime($user.LastUseTime) if(((get-date) - $last_active) -gt $timespan) { $user | Remove-WmiObject } } } There may be neater ways to do this but seems to work well enough in any case. --- EDIT --- Looks like it doesn't run so well on Windows 10. Works fine on Windows 7 and Server 2016 so will need to do some digging. Edited September 26, 2017 by Killer_Bot 1
chief_67 Posted October 4, 2017 Posted October 4, 2017 Hi Guys, Hope someone can help me I've used Warwick_Tech which works a treat when applied via group policy. But I need to edit the script for it to delete user profiles that are over 5 days old. Will anyone be able to help me, this is the script I'm using at the moment: $profiles = $null $profiles = Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\UpdatusUser"))} if ($profiles -ne $null) { $profiles | Remove-WmiObject } Exit
Steve21 Posted October 4, 2017 Posted October 4, 2017 Should be able to add something like this to the filter {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} And just change the 30 to whatever you want, five in your case I guess (Generally would suggest longer else you'll start wiping stuff everytime a halfterm is there, or a 2 week rotation timetable) Steve
Steve21 Posted October 4, 2017 Posted October 4, 2017 Oh sorry noticed you were using WMI not CIMs. Personally I'd do it like this via CIMs: Get-CimInstance win32_userprofile | Where {(!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\UpdatusUser") -and ($_.LastUseTime -lt $(Get-Date).Date.AddDays(-30))} Will have to test it locally for you as I haven't done so don't throw it out massively yet, but should work. (No doubt could work that into WMI too, but I know WMI does silly long-numbered last logins Steve
chief_67 Posted October 4, 2017 Posted October 4, 2017 The WIM is working fine for me as it's tried and tested, Steve21 so the script below should do the job for me with the added script you mentioned $profiles = $null $profiles = Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\UpdatusUser"))} {$_.LastWriteTime -lt (Get-Date).AddDays(-5)} if ($profiles -ne $null) { $profiles | Remove-WmiObject } Exit
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now