Jump to content

Recommended Posts

Posted

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.

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

Posted
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()
           }

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

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