404 Tech Support

PowerShell script to remove user profiles

Removing Windows profiles can be a little tricky. You cannot just delete the files under C:\Users or else the account will have problems logging in the next time with entries still in the registry.

The proper way to remove a profile manually in Windows is to go to System, click Advanced system settings, and under the Advanced tab of the System Properties window choose Settings under User Profiles. Find the profile you wish to remove and select delete. This will cleanly delete its files and registry entries. If you are having logon issues, you might back up that profile’s data and delete the profile with the previous method. Next time you login, the profile will start from the default profile and you can copy your data back to where it goes.

To script the process, you have similar problems in that you can’t just delete the files. Instead, we will have Windows functions do the removal for us. This PowerShell script will query for all Windows profiles and then it excludes Special profiles (like Default), the local Administrator, and other profiles. All other profiles will be deleted. I assigned this as a shutdown script so every shutdown or restart, all profiles are deleted.

https://gist.github.com/jhamilton09/d33569e6209ad36c9606

You will note that I had to exclude the UpdatusUser in my case as well. It was causing the script to error out because some files were in use and could not be removed. UpdatusUser is an account created by NVIDIA drivers with annoying side effects like this.