As you may have noticed by now, there doesn’t seem to be any nice built in way to set environmental variables in intune 🙁
The Problem
Setting a user environmental variable using powershell is an easy task to accomplish, you basically just run the following:
|
|
This works just fine, but won’t take effect until the user either reboots or signs into the device again. Which is obviously not ideal.
I spent a little time looking into this and i found out that when you change the environmental variable manually via the GUI, a WM_SETTINGCHANGE message is broadcast to the system and that refreshes them, but how you do that with powershell?
The Solution
As it turned out, my fellow sysmansquad member Grant Dickins had a solution to the problem.
|
|
Or if you need to set a system variable
|
|
Which both sets the variable and broadcasts the change to the rest of the system!
Putting it all together
Intune has a very nice feature called Proactive Remediation that is part of endpoint analytics. and its the perfect tool for the job!
If you are new to using Proactive Remediations, check out Jake Shackelford’s blog post, it will get you up to speed in no time.
When you create the Proactive remediation, you need to configure it to run as the logged-on user.
The Script
First up is the Detection script, pretty simple stuff, it checks if the temp and tmp variables are set to the path i want.
Note that if you want to use a different path, just change line 5 in both scripts.
|
|
The remediation is not much to write home about. It sets the variables and runs the code needed to refresh the system.
|
|
Outro
So there you go, a simple proactive remediation that you can use to change user environmental variables with relative ease. You can trivially adopt this to change any other variable. Either user or System variable.
Jóhannes Geir Kristjánsson Contributor
Microsoft MVP, enterprise mobility, Owner of winadmins discord and stunt guy on http://intune.training