bwexler Posted May 14, 2018 Posted May 14, 2018 I am trying to run a powershell script to delete old user profiles, but the script only deleted a few profiles and when i go into C:\users\ and select a profile it says that i don't have access.. I want to run this script as part of a Shutdown/Logoff GPO , so any help would be appreciated.
MrKJLS Posted May 14, 2018 Posted May 14, 2018 (edited) We use this for cleaning up profiles: https://helgeklein.com/free-tools/delprof2-user-profile-deletion-tool/ You just need to create a batch file picking what account you want to delete or want to keep. We run ours as a startup script Edited May 14, 2018 by MrKJLS
Arthur Posted May 14, 2018 Posted May 14, 2018 I want to run this script as part of a Shutdown/Logoff GPO You will need to do it via a shutdown script. Logoff won't work.
bwexler Posted May 14, 2018 Author Posted May 14, 2018 we have win10 machines.. i am told it doesn't work well on there, since there is an issue with how it picks up the date of the profile. We are a school and have a mixture of teachers & students signing on .
bwexler Posted May 14, 2018 Author Posted May 14, 2018 You will need to do it via a shutdown script. Logoff won't work. I had the script working when logged in, in powershell, but now im receiving the following error.
Arthur Posted May 14, 2018 Posted May 14, 2018 I had the script working when logged in, in powershell, but now im receiving the following error. Could you try the following PowerShell user profile deletion script? It's based on this script (which doesn't use Remove-WmiObject). #requires -RunAsAdministrator $Filter = '{0}{1}{2}{3}' -f 'Special=False AND Loaded=False AND LastUseTime<=',"'",$(Get-Date).Date.AddDays(-30),"'" Get-WmiObject -ClassName Win32_UserProfile -Filter $Filter | Add-Member -MemberType ScriptProperty -Name UserName -Value { (New-Object System.Security.Principal.SecurityIdentifier($this.Sid)).Translate([system.Security.Principal.NTAccount]).Value } -PassThru | ForEach-Object { Write-Output "Deleting $($_.LocalPath)" $_.Delete() }
bwexler Posted May 15, 2018 Author Posted May 15, 2018 Could you try the following PowerShell user profile deletion script? It's based on this script (which doesn't use Remove-WmiObject). #requires -RunAsAdministrator $Filter = '{0}{1}{2}{3}' -f 'Special=False AND Loaded=False AND LastUseTime<=',"'",$(Get-Date).Date.AddDays(-30),"'" Get-WmiObject -ClassName Win32_UserProfile -Filter $Filter | Add-Member -MemberType ScriptProperty -Name UserName -Value { (New-Object System.Security.Principal.SecurityIdentifier($this.Sid)).Translate([system.Security.Principal.NTAccount]).Value } -PassThru | ForEach-Object { Write-Output "Deleting $($_.LocalPath)" $_.Delete() } how can i include specific accounts to not delete.
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