I am importing a few users to AD through a CSV file. I am trying to get 2 things working.<\/p>\n
Manager name - I cannot get this to populate - What exactly will I need the header to be for the manager name in the CSV?<\/p>\n<\/li>\n
How can I add a different password for each user and enable the account. I was able to get this work by adding the Enable $True and also adding a generic password with convert to secure string only thing is this adds the password for all the users.<\/p>\n<\/li>\n
I havent tried yet - BUt how do I import these users into a specific OU?<\/p>\n<\/li>\n<\/ol>","upvoteCount":5,"answerCount":10,"datePublished":"2016-12-09T13:49:06.000Z","author":{"@type":"Person","name":"joesanfilippo2","url":"https://community.spiceworks.com/u/joesanfilippo2"},"acceptedAnswer":{"@type":"Answer","text":"
csv will contain<\/p>\n
fisrtname, lastname,password,manager\njack,sparrow,P@ssw0rd,Mr. Manager\n<\/code><\/pre>\nRemove email field if you do not want set ou<\/p>\n
<#\n#**************************************************BULK AD User Creation By Allenage.com*****************************************#\n version 0.1\n Just add fisrtname, lastname in the csv and place on C:\\ as users.csv \n\n Other changes\n\n $OU=\"CN=users, DC=Domain,DC=COM\" change OU path as desired.\n\nHere are examples of samaccountname or username comment out rest which does'nt suit your organistation and keep the required one.\n\n$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow\n #$Sam=$User.FirstName+$User.LastName example john snow will be Johnsnow\n #$Sam=$User.FirstName example john snow will be John\n #$Sam=$User.firstName + \".\" + $User.lastName example john snow will be John.snow\n #$Sam=$user.Lastname+$user.Firstname.Substring(0,1)) example john snow will be sjohn\n\n#>\nImport-module activedirectory\n$Users=Import-csv c:\\users.csv\n$a=1;\n$b=1;\n$failedUsers = @()\n$usersAlreadyExist =@()\n$successUsers = @()\n$VerbosePreference = \"Continue\"\n$LogFolder = \"$env:userprofile\\desktop\\logs\"\nForEach($User in $Users)\n{\n $User.FirstName = $User.FirstName.substring(0,1).toupper()+$User.FirstName.substring(1).tolower()\n $User.LastName = $User.LastName.substring(0,1).toupper()+$User.LastName.substring(1).tolower()\n $FullName = $User.FirstName + \" \" + $User.LastName\n $SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow\n #$Sam=$User.FirstName+$User.LastName example john snow will be Johnsnow\n #$Sam=$User.FirstName example john snow will be John\n #$Sam= $User.firstName + \".\" + $User.lastName example john snow will be John.snow\n #$Sam=$user.Lastname+$user.Firstname.Substring(0,1)) example john snow will be sjohn\n $dnsroot = '@' + (Get-ADDomain).dnsroot\n $SAM=$sam.tolower()\n $UPN = $SAM + \"$dnsroot\"\n $OU=\"CN=users, DC=Domain,DC=COM\"\n $email=$Sam + \"$dnsroot\"\n\ntry {\n if (!(get-aduser -Filter {samaccountname -eq \"$SAM\"})){\n New-ADUser -Name $FullName -AccountPassword (ConvertTo-SecureString $user.password -AsPlainText -force) -GivenName $User.FirstName -Path $OU -SamAccountName $SAM -Surname $User.LastName -UserPrincipalName $UPN -Manager $User.manager -EmailAddress $Email -Enabled $TRUE\n Write-Verbose \"[PASS] Created $FullName\"\n $successUsers += $FullName\n }\n \n}\ncatch {\n Write-Warning \"[ERROR]Can't create user [$($FullName)] : $_\"\n $failedUsers += $FullName\n}\n}\nif ( !(test-path $LogFolder)) {\n Write-Verbose \"Folder [$($LogFolder)] does not exist, creating\"\n new-item $LogFolder -type directory -Force \n}\n\nWrite-verbose \"Writing logs\"\n$failedUsers |ForEach-Object {\"$($b).) $($_)\"; $b++} | out-file -FilePath $LogFolder\\FailedUsers.log -Force -Verbose\n$successUsers | ForEach-Object {\"$($a).) $($_)\"; $a++} |out-file -FilePath $LogFolder\\successUsers.log -Force -Verbose\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2016-12-09T14:01:12.000Z","url":"https://community.spiceworks.com/t/import-users-to-ad-some-info-not-poulating/545984/3","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},"suggestedAnswer":[{"@type":"Answer","text":"I am importing a few users to AD through a CSV file. I am trying to get 2 things working.<\/p>\n
\n- \n
Manager name - I cannot get this to populate - What exactly will I need the header to be for the manager name in the CSV?<\/p>\n<\/li>\n
- \n
How can I add a different password for each user and enable the account. I was able to get this work by adding the Enable $True and also adding a generic password with convert to secure string only thing is this adds the password for all the users.<\/p>\n<\/li>\n
- \n
I havent tried yet - BUt how do I import these users into a specific OU?<\/p>\n<\/li>\n<\/ol>","upvoteCount":5,"datePublished":"2016-12-09T13:49:06.000Z","url":"https://community.spiceworks.com/t/import-users-to-ad-some-info-not-poulating/545984/1","author":{"@type":"Person","name":"joesanfilippo2","url":"https://community.spiceworks.com/u/joesanfilippo2"}},{"@type":"Answer","text":"
\n- \n
Whatever you have put as the title in your CSV you will need to reference in your script.<\/p>\n<\/li>\n
- \n
If you want to add a different password then you need to specify it in your script.<\/p>\n<\/li>\n
- \n
Specify the OU in your CSV and then reference it in your script.<\/p>\n<\/li>\n<\/ol>\n
I did this sort of thing a couple of months back and it took a lot of ‘Googling’, testings and essentially playing until I got it how I wanted it. I also used Windows Powershell ISE to build my script, which I found very, very useful. I’m sure there are other Powershell gurus on here who can probably simplify it down but that is basically how I went about it.<\/p>","upvoteCount":0,"datePublished":"2016-12-09T13:59:59.000Z","url":"https://community.spiceworks.com/t/import-users-to-ad-some-info-not-poulating/545984/2","author":{"@type":"Person","name":"jnfarmer","url":"https://community.spiceworks.com/u/jnfarmer"}},{"@type":"Answer","text":"