Hey Everyone,<\/p>\n
I am currently trying to create a large group of users in active directory using powershell. I am somewhat new to powershell, and I am coming across some issues.<\/p>\n
Here is the code I am trying to run:<\/p>\n
$Users = Import-Csv -Path \"<path>\" \nforeach ($User in $Users) \n{ \n $Displayname = $User.'Firstname' + \" \" + $User.'Lastname' \n $UserFirstname = $User.'Firstname' \n $UserLastname = $User.'Lastname' \n $OU = $User.'OU' \n $SAM = $User.'SAM' \n $Description = $User.'Description' \n $Password = $User.'Password' \n New-ADUser -Name \"$Displayname\" -DisplayName \"$Displayname\" -SamAccountName $SAM -UserPrincipalName $UPN -GivenName \"$UserFirstname\" -Surname \"$UserLastname\" -Description \"$Description\" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path \"$OU\" -ChangePasswordAtLogon $false –PasswordNeverExpires $true -server domain.loc \n}\n<\/code><\/pre>\nWhen I run the script above, I am getting the error “New-ADUser : Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.”<\/p>\n
I checked the AWDS and it is running, and I am running this script directly from the domain controller, so I am not sure why it is unable to contact the DC.<\/p>\n
Any help is appreciated!<\/p>","upvoteCount":2,"answerCount":8,"datePublished":"2017-06-06T16:42:47.000Z","author":{"@type":"Person","name":"bradpaschal","url":"https://community.spiceworks.com/u/bradpaschal"},"acceptedAnswer":{"@type":"Answer","text":"
If you have just one domain, you don’t really have to give it the server.<\/p>\n
Also $UPN is not defined.<\/p>\n
Maybe look into splatting<\/p>\n
Edit: it’s called splatting, not ‘platting’ lol >.><\/p>","upvoteCount":1,"datePublished":"2017-06-06T16:48:10.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hey Everyone,<\/p>\n
I am currently trying to create a large group of users in active directory using powershell. I am somewhat new to powershell, and I am coming across some issues.<\/p>\n
Here is the code I am trying to run:<\/p>\n
$Users = Import-Csv -Path \"<path>\" \nforeach ($User in $Users) \n{ \n $Displayname = $User.'Firstname' + \" \" + $User.'Lastname' \n $UserFirstname = $User.'Firstname' \n $UserLastname = $User.'Lastname' \n $OU = $User.'OU' \n $SAM = $User.'SAM' \n $Description = $User.'Description' \n $Password = $User.'Password' \n New-ADUser -Name \"$Displayname\" -DisplayName \"$Displayname\" -SamAccountName $SAM -UserPrincipalName $UPN -GivenName \"$UserFirstname\" -Surname \"$UserLastname\" -Description \"$Description\" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path \"$OU\" -ChangePasswordAtLogon $false –PasswordNeverExpires $true -server domain.loc \n}\n<\/code><\/pre>\nWhen I run the script above, I am getting the error “New-ADUser : Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.”<\/p>\n
I checked the AWDS and it is running, and I am running this script directly from the domain controller, so I am not sure why it is unable to contact the DC.<\/p>\n
Any help is appreciated!<\/p>","upvoteCount":2,"datePublished":"2017-06-06T16:42:47.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/1","author":{"@type":"Person","name":"bradpaschal","url":"https://community.spiceworks.com/u/bradpaschal"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n
<\/p>","upvoteCount":0,"datePublished":"2017-06-06T16:43:16.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
foreach ($User in (Import-Csv -Path \"<path>\"){\n $hash = @{\n Name = $User.'Firstname' + \" \" + $User.'Lastname'\n DisplayName = $User.'Firstname' + \" \" + $User.'Lastname'\n SamAccountName = $User.'SAM'\n UserPrincipalName = $upn # does not seem to be defined?\n GivenName = $User.'Firstname'\n Surname = $User.'Lastname'\n Description = $User.'Description'\n AccountPassword = (ConvertTo-SecureString $($User.'Password') -AsPlainText -Force)\n Enabled = $true\n Path = $User.'OU'\n ChangePasswordAtLogon = $false\n PasswordNeverExpires = $true # bad practise...tut tut\n server = 'dc01' # This would be the actual name of the server,\n # maybe try to just remove the server\n }\n New-ADUser @hash\n}\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2017-06-06T17:08:38.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"New-ADUser -Name $FullName -AccountPassword (ConvertTo-SecureString $password -AsPlainText -force) -GivenName $User.FirstName -Path $OU -SamAccountName $SAM -Surname $User.LastName -UserPrincipalName $UPN Enabled $TRUE\n<\/code><\/pre>\nwhy you are running this remotely?<\/p>","upvoteCount":2,"datePublished":"2017-06-06T17:12:04.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/5","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"
Is this a Server 2003 domain?<\/p>","upvoteCount":2,"datePublished":"2017-06-06T17:14:22.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/6","author":{"@type":"Person","name":"rockn","url":"https://community.spiceworks.com/u/rockn"}},{"@type":"Answer","text":"
Thanks for the help! It looks like it was the server specification causing the issue. I removed that and defined the upn and it went through no problem.<\/p>\n
That’s what I get for copy and paste from technet. Thanks!<\/p>","upvoteCount":1,"datePublished":"2017-06-06T17:38:06.000Z","url":"https://community.spiceworks.com/t/bulk-creating-users-in-active-directory-using-powershell/585582/7","author":{"@type":"Person","name":"bradpaschal","url":"https://community.spiceworks.com/u/bradpaschal"}},{"@type":"Answer","text":"
try this if you have any issues later<\/p>\n