I’m trying to include a function in a new user creation PowerShell script that will create a user’s home folder and provide the necessary permissions based on information retrieved from a file called mappings.CSV. I can’t seem to get this accomplished without using a bunch of static IF statements for each department code within the script itself.
New users are initially read in to an array from a .CSV file at the start of the script. A ForEach loop creates users one at a time assigning all of the appropriate variables, creating the user mailbox, etc. A 4 digit code in that file read in to a variable called $userDeptCode and is used successfully elsewhere in my script. I need it to also create a home directory.
In the first column of mappings.csv is a 4 digit department code. The second column is a UNC path for where the user’s home directory should be created. I can read in the file file, I just can’t seem to take the variable from $userDeptCode, match it to the code column of mappings.CSV, and assign the corresponding value in the ‘share’ column to $homedirectory. Sample CSV snippets are below:
So the end result: Based on the user who is read in from user.csv, compare his $deptcode value to the mappings array. Based on the match in the mappings array, assign the corresponding value for share.
How can I accomplish this? I seem to consistently follow the wrong path. This is the last part I need, and it appears I’ve saved the best for last.
I’ve already got the code written to create the home directory and assign the appropriate permissions for the user, I just can’t get this one part working properly.
Thanks in advance.