Dear friends,
I was googling around trying to get a script to help automatically add different users into different groups and came into below script.
I didn't really understand how to use these
$VARIABLES = @("")
or
(@("UserName") + $faculties)
or
if ($user.$faculty)
or
$user.$faculty
Can anyone help to explain a bit more what these variables mean? Many thanks.
The .csv contains different headers like username, group1(FACULTY01), group2(FACULTY02), group3(FACULTY03), etc..
$faculties = @("FACULTY01", "FACULTY02", "FACULTY03", "FACULTY04")
$csv = Import-csv C:\temp\test.csv -Header (@("UserName") + $faculties)
foreach ($user in $csv | Select-Object -Skip 1)
{
foreach ($faculty in $faculties)
{
if ($user.$faculty)
{
Add-ADGroupMember -Identity $user.$faculty -Member $user.UserName
}
}
}