Answered by:
Importing User from csv to AD using PS

Question
-
I have script which i have edited and i tried to run it from my machine(Windows 7) which has AD and permission for me to add and remove student user manually. I have a few question, do i need to run the script in the Domain controller server or could i just do it from my pc? secondly do you have any clue why im having this error below. Next, how do i change the path where the CSV. file is located(now its in C:windows\system32)? Thanks
My PSscript
Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter ";" -Path ".\userslist1.csv"
foreach ($User in $Users)
{
$OU = "OU=StudentOU,OU=UplandsSchool,DC=uplands,DC=com"
$Password = $User.password
$Detailedname = $User.firstname + " " + $User.name
$UserFirstname = $User.Firstname
$FirstLetterFirstname = $UserFirstname.substring(0,1)
$SAM = $FirstLetterFirstname + $User.name
New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.firstname -Surname $user.name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU
}Error message
PS C:\Users\cdoss> C:\Users\cdoss\Desktop\ADProject\Source4\UserCreate.ps1
New-ADUser : The server is unwilling to process the request
At C:\Users\cdoss\Desktop\ADProject\Source4\UserCreate.ps1:11 char:15
+ New-ADUser <<<< -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.firstname -Surname $user.name -AccountPassword (Con
vertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU
+ CategoryInfo : NotSpecified: (CN=Carlson MILL...=uplands,DC=com:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : The server is unwilling to process the request,Microsoft.ActiveDirectory.Management.Commands.NewADUserTuesday, July 16, 2013 12:25 AM
Answers
-
You can run this script from any domain joined machine or doing powershell remoting, not necessarily needs to be the DC. There can be many reason for this error, few listed in the previous discussion.
You can find few other ways to do import users using powershell.
Awinish Vishwakarma - MVP
My Blog: awinish.wordpress.com
Disclaimer This posting is provided AS-IS with no warranties/guarantees and confers no rights.- Proposed as answer by Meinolf Weber Tuesday, July 16, 2013 6:43 AM
- Marked as answer by Carlson Doss Tuesday, July 16, 2013 7:33 AM
Tuesday, July 16, 2013 1:33 AM
All replies
-
You can run this script from any domain joined machine or doing powershell remoting, not necessarily needs to be the DC. There can be many reason for this error, few listed in the previous discussion.
You can find few other ways to do import users using powershell.
Awinish Vishwakarma - MVP
My Blog: awinish.wordpress.com
Disclaimer This posting is provided AS-IS with no warranties/guarantees and confers no rights.- Proposed as answer by Meinolf Weber Tuesday, July 16, 2013 6:43 AM
- Marked as answer by Carlson Doss Tuesday, July 16, 2013 7:33 AM
Tuesday, July 16, 2013 1:33 AM -
Actually it is working now...the problem was CN=ORG not CN=COM
=)
Im new so i learned somethings. Thanks
Tuesday, July 16, 2013 7:34 AM