Delete user profile from registry

Hello all,

Can someone please help me how can I achieve this using powershell

I am trying to delete the user profile from registry "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" and also assocaited guid from “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileGuid”.

I tried the below commands

Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\')[-1] -eq 'username' } | Remove-CimInstance
Get-WMIObject -class Win32_UserProfile|?{$_.localpath -like "*Username*"}|Remove-WmiObject

when I use Get-wmiObject command, I get below error:

Remove-WmiObject : 
At line:1 char:75
+ .._UserProfile|?{$_.localpath -like "*username*"}|Remove-WmiObject|clip
+                                                      ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ( : ) [Remove-WmiObject], FileLoadEx 
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell 
1 Like

The commands are equivalent. So one of them is enough. And in this special case you should choose the first one. Do not use Get-WMIObject anymore.

Here you have a little more complete description:

Regardless of that - PLEASE format error messages as code using the preformatted text button ( </> ). Just like you do with code. As you can see when you review your own post the forum software will cut some charachters and symbols when you don’t use the proper formatting.

Thanks in advance.

1 Like

Thanks @Olaf for confirming the commands.

For the error that I am getting, can you suggest me what can be done. Is there any way that I can delete them using the Get-item and Remove-item.

I am struck, can you please help

The two commands you posted do the same. Just use the first one. The second one is unnecessary.

@Olaf ,

It says the file is in use and I am unable to delete the NTUSER.DAT in user profile C:\users\username as well as it says the file is opened by SYSTEM and unable to delete it.

Tried rebooting the machine and stopping Symantec protection, but still it’s same.

Actually, there are many profiles that are to be deleted. So using CIMInstance command it’s the same. It says file is in use.

If the file is in use you cannot delete it.