I came across a scenario today when I was helping during a migration project. We wanted to map a drive based on a value in extensionattribute on the user. First, we thought that we would solve it with a script, but then it hit me like a lightning bolt that it is possible to use group policy preferences for this.
So, how do we do it?
First go into the Group policy and then go to the Environment section and add a new one:
In my case I wanted an environment variable named oldsamaccountname:
Set the «Run in logged-on user’s security context» and «Item-level targeting» (This is where the magic happens)
Then I filled out the following:
-Attribute: extensionAttribute4 (this is the attribute you want to get)
-Environment variable name: oldsamaccountname
If you then logon to a client and run the set command it will show you the output and the variable is present:
Next you create a drive mapping as normal, except that you can use the newly created variable:
I know, Group Policy Preferences is probably not the hottest topic at the moment to blog about, but still I find it very useful.
Maybe this helps someone that is trying to solve this exact problem 🙂 .
This also shows that scripting is not always the solution. (OMG did I just write those words…)
As pointed out by Karl Magnus, you do not need to create a local variable just for drive maps. You could use the LDAP query directly within the drive mapping. If you however need the variable present on the client for other things, you will need to add it as a variable. Great feedback! Love it!