1

We are planning to use the EmployeeNumber user attribute in AD to create the path to each user's Home drive. Reason for this is that AD user names are currently based on last name, which changes often in our large domain. We want to get away from managing name changes. In the future we may transition to employee number as user name but we're not there yet.

Currently I am using a foreach loop in Powershell to accomplish setting the path for each user in AD, but I would like to investigate maybe using Group Policy Preferences so that I can set a friendly label on the mapped drive. However I'm stumped on getting the EmployeeNumber into the path.

How can I get the EmployeeNumber attribute into the user HomePath as a variable?

1
  • Can you please post your current work? Commented Feb 18, 2015 at 22:46

1 Answer 1

0

If you are asking how you can set a variable name in powershell and pick it up elsewhere in your system, you could export it as a system environment variable.

To do that you need to use a .net method called Environment.SetEnvironmentVariable, here is the documentation.

This is how you use it in powershell for different scopes currentprocess, currentuser or machine:

[environment]::SetEnvironmentVariable("variable_name","value","process") [environment]::SetEnvironmentVariable("variable_name","value","machine") [environment]::SetEnvironmentVariable("variable_name","value","user") 

If you want to delete the variable use $null in place of value.

To read it from within powershell you can use GetEnvironmentVariable, e.g:

[environment]::GetEnvironmentVariable("variable_name","machine") 

or you could $env:variable_name

or, from a regular command line you could %variable_name% and so on.

Without having tested it, I guess you could use it in a GPO too as long as you've predefined the variable on the machine where it needs to be interpreted, perhaps through a GPO triggered script processed earlier in the chain?

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.