The task is to create users in AD and add them to existing groups.<\/p>\n
That`s the CSV file:<\/p>\n
That`s the script:<\/p>\n
That`s the error:<\/p>\n
How can this be resolved? (Not sure the script is even correct, but for now can`t execute so no way to check)<\/p>","upvoteCount":2,"answerCount":10,"datePublished":"2017-09-06T18:33:32.000Z","author":{"@type":"Person","name":"mwinds","url":"https://community.spiceworks.com/u/mwinds"},"acceptedAnswer":{"@type":"Answer","text":"
Try it like so:<\/p>\n
Import-Module ActiveDirectory\n\n$dcname = 'dc01' #add you DC name here\n\nImport-Csv \"C:\\Scripts\\orgusers.csv\" | \nForEach-Object {\n $prop = @{\n name = $_.name\n path = $_.parentou\n SamAccountName = $_.samaccountname\n UserPrincipalName = $_.\"samAccountName\" + \"@lovely.Local\"\n AccountPassword = (ConvertTo-SecureString \"Pa$$w0rd\" -AsPlainText -Force)\n Enabled = $true\n Server = $dcname\n \n }\n New-ADUser @prop\n \n Add-ADGroupMember -Identity $_.group -Members $_.name -Server $dcname\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2017-09-07T04:07:59.000Z","url":"https://community.spiceworks.com/t/create-users-in-ad-and-add-them-to-groups/604304/7","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"The task is to create users in AD and add them to existing groups.<\/p>\n
That`s the CSV file:
<\/p>\n
That`s the script:<\/p>\n
That`s the error:<\/p>\n
How can this be resolved? (Not sure the script is even correct, but for now can`t execute so no way to check)<\/p>","upvoteCount":2,"datePublished":"2017-09-06T18:33:32.000Z","url":"https://community.spiceworks.com/t/create-users-in-ad-and-add-them-to-groups/604304/1","author":{"@type":"Person","name":"mwinds","url":"https://community.spiceworks.com/u/mwinds"}},{"@type":"Answer","text":"
The script and the error seems to be missing?<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>","upvoteCount":2,"datePublished":"2017-09-06T18:58:00.000Z","url":"https://community.spiceworks.com/t/create-users-in-ad-and-add-them-to-groups/604304/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Maybe something like this:<\/p>\n
$DCName = \"dcserver01\"\n\nforeach($aduser in (import-csv \"c:\\file.csv\")){\n $props = @{\n SamAccountName = $aduser.SamAccountName\n name = $aduser.name\n path = $aduser.parentou\n server = $DCName\n }\n New-ADUser @props\n\n Add-ADGroupMember -Identity $aduser.group -Members $aduser.SamAccountName -Server $DCName\n}\n\n<\/code><\/pre>\nYou want to give it the same servername (that assumes you have multiple DC) so you have no issues with replication.
\nIt also assumes the Groups names you have in your CSV is that actual name of a group.<\/p>","upvoteCount":0,"datePublished":"2017-09-06T19:33:49.000Z","url":"https://community.spiceworks.com/t/create-users-in-ad-and-add-them-to-groups/604304/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Yes, it disappeared. That`s the code:<\/p>\n
Import-Module ActiveDirectory\nImport-Csv \"C:\\Scripts\\orgusers.csv\" | ForEach-Object {\n $userPrincinpal = $_.\"samAccountName\" + \"@lovely.Local\"\nNew-ADUser -Name $_.Name `\n -Path $_.\"ParentOU\" `\n -SamAccountName $_.\"samAccountName\" `\n -UserPrincipalName $userPrincinpal `\n -AccountPassword (ConvertTo-SecureString \"Pa$$w0rd\" -AsPlainText -Force) `\n -Enabled $true\nForeach-Object {add-adgroupmember -Identity $_.group -Members $_.name}\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2017-09-07T03:07:31.000Z","url":"https://community.spiceworks.com/t/create-users-in-ad-and-add-them-to-groups/604304/4","author":{"@type":"Person","name":"mwinds","url":"https://community.spiceworks.com/u/mwinds"}},{"@type":"Answer","text":"And that`s the error: