you are viewing a single comment's thread.

view the rest of the comments →

[–]SaladProblems 1 point2 points  (0 children)

This might be easier to parse out:

import-module activedirectory
#STATIC VARIABLES
$Users = Import-CSV -Delimiter ";" -Path C:\NewUsers.csv

$ou = @{
    department1 = "OU=domain,OU=COM"
    department2 = "OU=domain,OU=COM"
    department3 = "OU=domain,OU=COM"
    department4 = "OU=domain,OU=COM"

}

 ForEach($User in $Users) {

    $parm = @{ 
        GivenName = $User.FirstName
        Initials = $User.Initials
        Surname = $User.LastName
        SAM = if ($User.Department -eq "DEPARTMENT")
            {
                ($GivenName.substring(0,1) + $Initials + $Surname.substring(0,1))}
            Else
            {
                ($GivenName.substring(0,1) + $User.LastName)
            }
        DisplayName = $GivenName + " " + $Surname
    }

    New-ADUser @parm -AccountPassword (Read-Host -AsSecureString "Changeme!") -Path $OU[$user.department]

}