Importing User from csv to AD using PS RRS feed

  • 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.NewADUser

    Tuesday, July 16, 2013 12:25 AM


All replies