Hi , I have those users, from a csv script, and I sorted them all in OU (related as office in my script column). But in my OU there are others OU(related as departement) and I need to classify them into those to!
So in my script “Comptabilite” refeirs as $office and “Reglements locaux” as $dept.
To sorted the users that belong in “Comptabilite”, “Financements”,“Gestion des contrats” and “Unite Siege” ($office), I did this script and it was sucessful
foreach ($user in $users){ $name = $user.firstName + " " + $user.lastName $fname = $user.firstName $lname = $user.lastName $login = $user.firstName + "." + $user.lastName Uoffice = $user.office $Upassword = $user.password $dept = $user.department switch($user.office){ "Comptabilite" {$office = "OU=Comptabilite,OU=Exercise1,DC=college,DC=local"} "Unite Siege" {$office = "OU=Unite Siege,OU=Exercise1,DC=college,DC=local"} "Financements" {$office = "OU=Financements,OU=Exercise1,DC=college,DC=local"} "Gestion des contrats" {$office = "OU=Gestion des contrats,OU=Exercises,DC=college,DC=local"} default {$office = $null} } try { New-ADUser -Name $name -SamAccountName $login -UserPrincipalName $login -DisplayName $name -GivenName $fname -Surname $lname -AccountPassword (ConvertTo-SecureString $Upassword -AsPlainText -Force ) -Path $office -Department $dept -Enabled $true echo "Utilisateur ajouté : $name" } catch{ echo "utilisateur non ajouté : $name" } }
Following the logic did this script to sort them into my “departement” named “Reglements locaux” and it wasn’t very successful
foreach ($user in $users){ $name = $user.firstName + " " + $user.lastName $fname = $user.firstName $lname = $user.lastName $login = $user.firstName + "." + $user.lastName $Uoffice = $user.office $Upassword = $user.password $dept = $user.department switch($user.departement){ "Reglements locaux" {$dept = "OU=Reglements locaux,OU=Comptabilite,OU=Exercise1,DC=college,DC=local"} default {$dept = $null} } try { Add-ADUser -Name $name -SamAccountName $login -UserPrincipalName $login -DisplayName $name -GivenName $fname -Surname $lname -AccountPassword (ConvertTo-SecureString $Upassword -AsPlainText -Force ) -Path $dept -Department $dept -Enabled $true echo "Utilisateur ajouté : $name" } catch{ echo "utilisateur non ajouté : $name"} }
I also tried to put “Move-ADUser” instead of “Add-ADUser” but it still doesnt work. I give me my list of users with the mention “not added”
No error message neither! Can somenone help?