Jump to content

Recommended Posts

Posted

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

Posted
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.

  • Thanks 1
Posted
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.

Posted

@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...

  • Thanks 1
Posted
@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?

Posted

+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

  • Thanks 1
Posted

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!

Posted
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 "
Posted
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'?

Posted
+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"

 

DeleteProfilesPS_Script.png

Posted

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

Posted (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 by dapaulio
Posted
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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...