How can I remove domain profiles in Windows while excluding the logged-in user?

0
1
Asked By TechWanderer42 On

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

Answered By AdminWhizKid On

We actually use Group Policy for managing profiles on our end. It's a lot smoother that way!

Answered By RMMGuru007 On

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!

Answered By GPOFanatic On

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

Answered By ProfileCleaner99 On

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!

Answered By ScriptMaster2023 On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.