hakk

software development, devops, and other drivel
Tree lined path

When Environment Variables Mysteriously Reset...

Ran into a frustrating issue recently where a custom environment variable kept resetting itself every time a system rebooted. I wasn’t sure what was causing this I was notified that the team had changed all necassary items to correct this but it kept occurring. After some digging it turns out it was being overwritten by a GPO startup script.

How did I find it? PowerShell, of course:

Get-ChildItem -Path "\\domain.name\SYSVOL\domain.name\Scripts" -Recurse -File | Select-String -Pattern "MY_ENV_VAR"

I searched the SYSVOL scripts directory on the domain controller, and sure enough, one of the logon scripts was setting the variable back to a default value.

Lesson learned: When environment variables keep reverting, check for:

  • Startup or logon scripts set via GPO
  • Scheduled tasks or service startup commands
  • Scripts in \\domain\SYSVOL\domain\Scripts or referenced by GPO

This kind of behavior can be easy to overlook, especially in larger environments with years of legacy policies. PowerShell made the detective work quick and repeatable.

Don’t forget to document which scripts are modifying your environment — future-you will thank you.