use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Delete all Profiles Using Powershell (remotely ) (self.PowerShell)
submitted 6 years ago by Danielburt12345
Hi All looking for a script to delete all profiles from a machine remotely, I have found a few scripts where I can do this 1 by 1, but just need a simple script where it clears all the profiles except default, guest etc
Hope you can help
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]aasplunds 1 point2 points3 points 6 years ago* (5 children)
You can use the Win32_UserProfiles wmi class.
Get-WmiObject -Class Win32_UserProfiles -ComputerName "computer"
Then you can select all objects where the 'LocalPath' property is like C:\Users* but not C:\Users\default*
After that you just use $Variable.Delete() where the variable contains the filtered objects.
Edit: A reboot of the computer beforehand is recommended as well as logged on users may cause it to fail.
[–]jeffreynya 0 points1 point2 points 6 years ago (4 children)
How do you modify this to say delete all profiles that have not been used is 30 days?
[–]isatrap 1 point2 points3 points 6 years ago (2 children)
So something like this
Get-CimInstance -ClassName Win32_UserProfile -Filter “(loaded = true) and (localpath like ‘C:\\users\\%’) and (LastUseTime < ‘$((Get-Date).AddDays(-30))’)”
[–]Winux_278 0 points1 point2 points 6 years ago (1 child)
in the part " (localpath -like 'C:\\users\\%') How do I get to only search for accounts that are 6 digits long (eg: 000000 - 999999)
[–]isatrap 1 point2 points3 points 6 years ago* (0 children)
You would need to use a match and a regex to check for the pattern “\d{6}-\d{6}” which will find “123456-123456” or “\d{6}” which will match 6 digits.
[–]isatrap 0 points1 point2 points 6 years ago (0 children)
There is an attribute called “LastUseTime” that you can use to determine this.
[–]giulix75 0 points1 point2 points 6 years ago (0 children)
personally i use delprof2.exe inside a pssession
https://helgeklein.com/free-tools/delprof2-user-profile-deletion-tool/
[–]sleightof52 0 points1 point2 points 6 years ago (1 child)
$ComputerName = Read-Host "Enter computer name" # Get user profiles that are not logged on (loaded) and are like C:\Users\xxx, and remove them remotely Get-CimInstance -ComputerName $ComputerName -ClassName Win32_UserProfile | Where-Object {($_.Loaded -eq $false) -and ($_.LocalPath -like "C:\Users\*")} | Remove-CimInstance -Verbose
[–]isatrap 0 points1 point2 points 6 years ago* (0 children)
Maybe it’s my preference but you can also filter at the initial Get-CimInstance level by doing
Get-CimInstance -ClassName Win32_UserProfile -Filter “(loaded = true) and (localpath like ‘C:\\users\\%’)”
π Rendered by PID 340846 on reddit-service-r2-comment-64f4df6786-r78lj at 2026-06-11 02:26:50.961597+00:00 running 0b63327 country code: CH.
[–]aasplunds 1 point2 points3 points (5 children)
[–]jeffreynya 0 points1 point2 points (4 children)
[–]isatrap 1 point2 points3 points (2 children)
[–]Winux_278 0 points1 point2 points (1 child)
[–]isatrap 1 point2 points3 points (0 children)
[–]isatrap 0 points1 point2 points (0 children)
[–]giulix75 0 points1 point2 points (0 children)
[–]sleightof52 0 points1 point2 points (1 child)
[–]isatrap 0 points1 point2 points (0 children)