Remotely remove a broken user profile from another computers registry when the user folder is deleted

I recently had an issue where someone had deleted my admin user profile from a remote server by deleting its folder.
The logon then failed as Windows still expected the folder to be there, as obviously the registry entries were not removed.
Rather than manually checking HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList for the SID and then removing it WMIC can be used. A user called Tommylotmanagement posted an answer and I found it worked if the user folder profile has been deleted as well.

wmic /node:<Server> path win32_UserProfile where LocalPath="c:\\users\\<ADUsername>" Delete 2>>c:\windows\temp\wmic.err

It should then show:
Deleting instance \\<Server>\root\cimv2:Win32_UserProfile.SID=”<SID>”
Instance deletion successful

If it fails check the file c:\windows\temp\wmic.err in a text editor.

Credit: Tommylotmanagement

I have also found this has worked to correct issues where accounts keep generating TEMP or TEMP. folders.