I had an issue at work that occasionally requires a user’s profile to be recreated, and found a way to get this done in PowerShell.

Normally, to delete a user profile in Windows 8 requires going into System Properties, on the Advanced Tab, and clicking Settings under User Profiles, finding the profile and deleting it.

Step 1: Get Into PowerShell

Note: I’ve done all of this on a virtual machine running Windows 8.1. The commands will also work fine on Windows 7 and 10.

If you’re like me and like to find ways to avoid the GUI, you can open a PowerShell window as Administrator and use the following:

Get-WMIObject -Class Win32_UserProfile

That will list information on all profiles running on the local computer. There’s quite a bit of information though, and most of it doesn’t mean much to me:

PS User Profile Image

We can pare this down, however. What I’m looking for is the path to the user’s profile folder in Windows. I can see that under the LocalPath property. Now I can get a cleaner list of profiles by selecting just the properties I need:

Get-WMIObject -Class Win32_UserProfile | select LocalPath

This returns the same list of user profile objects, but only shows the one property for each object we need:

PS User Profile Image 2

Select the Profile to be deleted

Get-WMIObject -Class Win32_UserProfile | where {($.LocalPath -eq 'c:\users\cwall')} | select LocalPath

The above code will only return the one object where LocalPath matches the one on the profile I need to delete. I tacked the Select statement back on the end so it returns only the LocalPath property.

PS User Profile Image 3

I’m moving slowly here because PowerShell is dangerous, and if I don’t make sure the right profile is selected, PowerShell has no problem deleting the wrong one, or even trying to remove everything if I failed to specify one object. The Windows GUI will ask for confirmation; PowerShell won’t.

Remove the Profile and confirm that it’s gone

We’re going to pipe the last command, which selects only one object, into Remove-WMIObject to delete it:

Get-WMIObject -Class Win32_UserProfile | where {($.LocalPath -eq 'c:\users\cwall')} | Remove-WMIObject

Powershell takes a minute to do its work, and returns just a prompt back. I can return the previous list of user profiles by localpath to see if the one I targeted is now gone:

PS User Profile Image 4

The profile for “cwall” is now gone. When the user logs back into that computer, the profile will be recreated.

The next step building onto this would be to remove the profile remotely. In my workplace this wasn’t necessary though, so I’ll stop here.