Windows OS
--
Questions
--
Followers
Top Experts
can someone please advise:
$profiles = $null
$profiles = Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\Public") -and ($_.LocalPath -ne "C:\Users\Default"))}
if ($profiles -ne $null) {
$profiles | Remove-WmiObject
}
Exit
powershell error attached that appears many many times at startup..

Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Thanks
Alex
Delete Local Profiles - folders in C:\Users etc.
Get-WMIObject -class Win32_UserProfile | Where {(!$_.Special) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-5))} | Remove-WmiObject
That'll do it, you'd be better off using group policy though
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






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I am using Alias (Shorthand)
GWMI -class Win32_UserProfile | ? {!$_.special -and $_.localpath -notmatch "administrator"} | Remove-WMIObject -whatif
Get-WMIObject -class Win32_UserProfile | Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator.sls") -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\Public") -and ($_.LocalPath -ne "C:\Users\Default"))} | Remove-WMIObject
errors:
Remove-WMIObject :
At line:1 char:275
+ ... lic") -and ($_.LocalPath -ne "C:\Users\Default"))} | Remove-WMIObject
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ~~~~~~~~~~~~~~~~
  + CategoryInfo      : InvalidOperation: (:) [Remove-WmiObject], COMException
  + FullyQualifiedErrorId : RemoveWMICOMException,Micr
Â
Remove-WMIObject :
At line:1 char:275
+ ... lic") -and ($_.LocalPath -ne "C:\Users\Default"))} | Remove-WMIObject
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ~~~~~~~~~~~~~~~~
  + CategoryInfo      : InvalidOperation: (:) [Remove-WmiObject], COMException
  + FullyQualifiedErrorId : RemoveWMICOMException,Micr
Â
Remove-WMIObject :
At line:1 char:275
+ ... lic") -and ($_.LocalPath -ne "C:\Users\Default"))} | Remove-WMIObject
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ~~~~~~~~~~~~~~~~
  + CategoryInfo      : InvalidOperation: (:) [Remove-WmiObject], COMException
  + FullyQualifiedErrorId : RemoveWMICOMException,Micr
Â
Remove-WMIObject :
At line:1 char:275
+ ... lic") -and ($_.LocalPath -ne "C:\Users\Default"))} | Remove-WMIObject
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ~~~~~~~~~~~~~~~~
  + CategoryInfo      : InvalidOperation: (:) [Remove-WmiObject], COMException
  + FullyQualifiedErrorId : RemoveWMICOMException,Micr
Â
Remove-WMIObject :
At line:1 char:275
+ ... lic") -and ($_.LocalPath -ne "C:\Users\Default"))} | Remove-WMIObject
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ~~~~~~~~~~~~~~~~
  + CategoryInfo      : InvalidOperation: (:) [Remove-WmiObject], COMException
  + FullyQualifiedErrorId : RemoveWMICOMException,Micr

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Get-WMIObject -class Win32_UserProfile |
Where {((!$_.Special) -and ($_.LocalPath -ne "C:\Users\Administrator") -and ($_.LocalPath -ne "C:\Users\Public") -and ($_.LocalPath -ne "C:\Users\Default"))} |
ForEach-Object { $_.Delete() }






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Windows OS
--
Questions
--
Followers
Top Experts
This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.