How can I delete a folder from all user profiles in Active Directory?

0
6
Asked By TechSavvyDude42 On

Hey everyone, I'm looking for help with a challenge I'm facing in my organization. We have around 1,000 users in an Active Directory environment, and the end users don't have local admin rights on their machines. I've created a PowerShell script that works when I log into each PC with admin rights, but doing this individually for all users is impractical. I want to automate the process of deleting specific folders from each user profile without needing to log in to every single machine. Here's the script I'm currently using:

```powershell
Get-Process -Name javaw | Stop-Process -Force
Remove-Item C:Users*APP -Force -Recurse
Remove-Item -Path "C:Users*.licence"
Remove-Item -Path "C:Users*.certs"
Remove-Item -Path "C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUp*"
Remove-Item -Path "C:Users*AppDataRoamingMicrosoftWindowsStart MenuProgramsStartup"
```

I'm open to any suggestions or insights on how to handle this! Thanks in advance!

3 Answers

Answered By ScriptMaster On

There’s a simple way to tackle this. If you create a GPO with your script as a login script, it should work perfectly. Just make sure that your script is safe and not deleting any crucial data. Always test it thoroughly before deployment, and filter its application to only the necessary machines.

Answered By SysAdminPro On

Since you're using Active Directory, setting up a Group Policy Object (GPO) could be your best bet. You can either run a script during the startup or login process through the GPO that targets specific files for deletion. Just ensure you test thoroughly before rolling it out to avoid any unwanted consequences.

Answered By ITGuru99 On

You can use Active Directory login scripts to automate this process. Try implementing a method similar to Intune that checks for specific files and then drops a flag file in the filesystem. Once that’s done, you can trigger the cleanup based on what is detected. Just remember to include logging so you can track what’s being deleted, and definitely limit the script's scope to prevent accidental data loss.

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.