Hey everyone! I'm trying to figure out how to remove domain profiles from Windows machines without affecting the currently logged-in user. I noticed that when I run my script, it indicates that the user is 'SYSTEM'. I would appreciate it if someone could take a look at my script and help me identify what I might be doing wrong. I'm deploying this script through RMM tools. Thanks in advance for any advice! Here's the script: https://pastebin.com/BAVQg3gH
5 Answers
We actually use Group Policy for managing profiles on our end. It's a lot smoother that way!
Running RMM tools typically means they operate as LocalSystem. You can get the current user with this command: (Get-CimInstance -ClassName Win32_ComputerSystem).UserName. Also, have you thought about doing it the standard way instead? Instead of deleting from the registry, try using: Get-CimInstance -ClassName Win32_UserProfile | Remove-CimInstance. It might save you some headache!
Check out this guide for using GPO to delete user profiles older than a certain number of days: https://learn.microsoft.com/en-us/archive/technet-wiki/28647.group-policy-how-to-automatically-delete-user-profiles-older-than-certain-number-of-days
It sounds like you're having a tough time with profile removal. What’s your end goal here? Are you trying to clear out old profiles from the machines? Just want to make sure I understand your intentions before suggesting a better method!
If your script runs as System, that's why it always shows SYSTEM as the user! To get the currently logged-in user, run the script as that user instead. Also, have you considered using Group Policy to delete profiles after a certain period of inactivity? It can simplify things for you. Additionally, consider the CIM method for deleting user profiles rather than just messing with the registry.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures