Sam_ Posted May 9, 2018 Posted May 9, 2018 Looking for a script to delete user profiles which works on both Windows 7 and 10, I found the below on another forum but doesnt seem to work. I would like to use WMI though and specify days old if possible. Get-WMIObject -class Win32_UserProfile | Where {(!$_.Special) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-5))} | Remove-WmiObject Thanks for any help
StevieM Posted May 9, 2018 Posted May 9, 2018 Looking for a script to delete user profiles which works on both Windows 7 and 10, I found the below on another forum but doesnt seem to work. I would like to use WMI though and specify days old if possible. This sounds like a job for Delprof2. 1
colly72 Posted May 9, 2018 Posted May 9, 2018 Some reports that Delprof2 doesn't work reliably with Windows 10, although I've not tested it properly here. Can you not just utilise Group Policy? https://social.technet.microsoft.com/wiki/contents/articles/28647.how-to-automatically-delete-user-profiles-older-than-a-certain-number-of-days-using-group-policy.aspx
Sam_ Posted May 9, 2018 Author Posted May 9, 2018 This sounds like a job for Delprof2. Yeah might give it a go! Some reports that Delprof2 doesn't work reliably with Windows 10, although I've not tested it properly here. Can you not just utilise Group Policy? https://social.technet.microsoft.com/wiki/contents/articles/28647.how-to-automatically-delete-user-profiles-older-than-a-certain-number-of-days-using-group-policy.aspx Have had that enabled for a couple of weeks but for whatever reason, group policy does not work in deleting user profiles, I havent actually heard of anyone successfully even use it.
bossman Posted May 9, 2018 Posted May 9, 2018 @Sam_ It seems that the GPO in question should do just what it is setup to do but because the timestamp on the profile is checked for the date and time it creates a flag which has its own timestamp of current time and date so inevitably it is never flagged as being outside of the timescale for deletion..... crazy really.... This is what we found anyway so we just use a batch script on shutdown which works very well for us... 1
Sam_ Posted May 9, 2018 Author Posted May 9, 2018 @Sam_ It seems that the GPO in question should do just what it is setup to do but because the timestamp on the profile is checked for the date and time it creates a flag which has its own timestamp of current time and date so inevitably it is never flagged as being outside of the timescale for deletion..... crazy really.... This is what we found anyway so we just use a batch script on shutdown which works very well for us... Wow that is crazy! Would have thought Microsoft would have fixed it by now but then again, who am I kidding Would you mind sharing what script you use to clear your profiles please?
Oaktech Posted May 9, 2018 Posted May 9, 2018 Delprof2 as a scheduled task with the scheduled task applied by GPO and set to run as system is working perfectly for us. 1
Jordan1 Posted May 9, 2018 Posted May 9, 2018 We use Delprof2 on Windows 7 Machines. Haven't tested on properly on Windows 10 as of yet.
HPlum78 Posted May 9, 2018 Posted May 9, 2018 https://gallery.technet.microsoft.com/scriptcenter/Remove-UserProfile-Remove-96e27a3b
dapaulio Posted May 9, 2018 Posted May 9, 2018 +1 delprof 2. running in a shutdown script works fine here applied via GP. I think some people find issues with permissions when running under a local schedule task. run the script from your netlogon share \\domain\netlogon\delprof2\delprof2.exe /u /i /d:100 /ed:local_admin /ed:domain_admin 1
Sam_ Posted May 9, 2018 Author Posted May 9, 2018 https://gallery.technet.microsoft.com/scriptcenter/Remove-UserProfile-Remove-96e27a3b I did try that one but does not work on Windows 10 unfortunately. +1 delprof 2. running in a shutdown script works fine here applied via GP. I think some people find issues with permissions when running under a local schedule task. run the script from your netlogon share \\domain\netlogon\delprof2\delprof2.exe /u /i /d:100 /ed:local_admin /ed:domain_admin Great thanks everyone for their replies, will try delprof 2!
bwexler Posted May 14, 2018 Posted May 14, 2018 I have issue in that the script worked on deleting some profiles, but others didnt delete and when i went in to C:\users\ i got "you don't have permission to access this "
StevieM Posted May 14, 2018 Posted May 14, 2018 I have issue in that the script worked on deleting some profiles, but others didnt delete and when i went in to C:\users\ i got "you don't have permission to access this " Did you 'Run as administrator'?
bwexler Posted May 14, 2018 Posted May 14, 2018 +1 delprof 2. running in a shutdown script works fine here applied via GP. I think some people find issues with permissions when running under a local schedule task. run the script from your netlogon share \\domain\netlogon\delprof2\delprof2.exe /u /i /d:100 /ed:local_admin /ed:domain_admin Does this look correct ? when i run the code "Arguments" directly in cmd prompt i get an error stating " ignoring profile , reason: not old enough to be deleted"
victory2015 Posted May 14, 2018 Posted May 14, 2018 If anyone wants a vbs script to delete profiles on remote machines here's one i use regularly. Prompts for username and computername and also deletes profile from server too. On Error Resume Next'open the file system objectSet oFSO = CreateObject("Scripting.FileSystemObject")set WSHShell = wscript.createObject("wscript.shell")Dim computername 'computernameDim username 'username'First param is message text, second is message titleusername = InputBox("Enter Username for profile deletion","Roaming Profile Deletion Tool")computername = InputBox("Enter computer to delete profile from (Leave blank to just delete roaming profile) ","Roaming Profile Deletion Tool")Call WSHShell.Run("\\SERVER\NETLOGON\Tools\DelProf2.exe /c:\\" & computername & " /r /u /id:" & username & "")strPath = "\\fileserver\profiles$\" & username & ".v6"DeleteFolder strPathFunction DeleteFolder(strFolderPath)Dim objFSO, objFolderSet objFSO = CreateObject ("Scripting.FileSystemObject")If objFSO.FolderExists(strFolderPath) Then objFSO.DeleteFolder strFolderPath, TrueEnd IfSet objFSO = NothingEnd Function
Arthur Posted May 14, 2018 Posted May 14, 2018 I am now getting this error when running the script www.edugeek.net/forums/windows-10/196087-powershell-script-not-working-due-acl-issues.html#post1676386
dapaulio Posted May 15, 2018 Posted May 15, 2018 (edited) Does this look correct ? when i run the code "Arguments" directly in cmd prompt i get an error stating " ignoring profile , reason: not old enough to be deleted" [ATTACH=CONFIG]48943[/ATTACH] Is the profile younger than 100 days? the age switch is d:100 part. if you wanted to reduce it then you would change this value to /d:30 for example for 30 days. I use 100 days so that peoples roaming profiles don't get removed over summer. I would run the arguments in the cmd line rather than in group policy so create a file called Delprof2.cmd in the same folder as delprof2.exe delprof2.cmd \\domain\netlogon\delprof2\delprof2.exe /u /I /d:100 /ed:localadmin /ed:mydomainadmin then create a group policy and point this cmd file in computer | Policy | Windows Settings | Scripts | Shutdown Script I would advise against putting it in a startup script for the obvious reason boot time will be significantly extended whilst it performs the task. Edited May 15, 2018 by dapaulio
bwexler Posted May 15, 2018 Posted May 15, 2018 Is the profile younger than 100 days? the age switch is d:100 part. if you wanted to reduce it then you would change this value to /d:30 for example for 30 days. I use 100 days so that peoples roaming profiles don't get removed over summer. I would run the arguments in the cmd line rather than in group policy so create a file called Delprof2.cmd in the same folder as delprof2.exe delprof2.cmd \\domain\netlogon\delprof2\delprof2.exe /u /I /d:100 /ed:localadmin /ed:mydomainadmin[/Code] then create a group policy and point this cmd file in computer | Policy | Windows Settings | Scripts | Shutdown Script I would advise against putting it in a startup script for the obvious reason boot time will be significantly extended whilst it performs the task. Yes i have profiles that show up as older than 100 days. Also how would you suggest running this As Administrator, in case the users don't have admin rights on the computer?
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