PS Script to Add Users to AD Groups by looking up Job Title from Reference file

Hello All,

I am new to powershell environment especially active directory module. I am working in a small firm and we are still on windows 2008 R2 Server. Being said that, I am currently trying to find out a way to setup a script for an day to day activity.

I have 2 CSV files

  1. Input file (that has Emp ID,User Name/SAM Account,Job_Title, Account_Status,AD_Group_Status,Has office email (Y or N))

Image: https://ibb.co/MVhv6Xc

2. Lookup groups file (that has Job_title, ADGroup names).

Image: lp — ImgBB

Based on the data on input file. I am trying to apply a logic by keeping Job_Title as a lookup/comparing field between these 2 files.

Example:

The input file has 4 user entries, with different job titles namely,
Technician
Admin
End User
Customer

The group files, has regarding AD Groups (2 or 3 groups for each title).

Job_Title ADGroupName
Technician Tech Group1
Technician Tech Group2
Technician Tech Group3
Technician Default Group x
Admin Admin Group1
Admin Admin Group1
Admin Default Group x
End User Enduser group1
End User Default Group x
Customer Customergroup1
Customer Customergroup2
Customer Default Group x

So, based on the job title, the groups needs to be added to sam accounts (in input file).

I am not sure if the whole thing can be done in one single scripting executionable file or do I have to break up into multiple script file with call reference to each files. This also needs to export logs?

 

pls help

If I got you right you can use nested foreach loops to achieve what you need. What do you have already? When you post code, please format it as code. That would be nice for sample data as well.