locked
Cannot create new users from csv RRS feed

  • Question

  • Hi,

    I am trying to create test users to see how this works. We will have few projects where I need to import users from csv and the clients will give us that file but when I try this i receive an error. Basically my test notepad file has those fields 

    LoginName,Department,City,Title,FirstName,LastName and the values for every field but when I try to import that I get an error.

    Import-Csv C:\Users.csv | New-ADUser -Path "OU=Test,DC=domain,DC=com"

    Error:New-ADUser : The input object cannot be bound because it did not contain the information required to bind all mandatory parameters:

    If I open one AD user, I have the field First Name and Last Name which means that I have all required fields so what is going on?

    Tuesday, October 17, 2017 12:12 PM

Answers

  • Hi,

    Everytime when you need to know something about the object pipe it to a gm.

    Get-aduser -filter * | gm

    Do you see first and the last name there and same is for login name? First name is the Givenname and the last name is the Surname so that needs to be changed and samaccountname is the login name. You have to have samaccountname.  You can change them in csv file but it is better that you use hashtable for it. 


    Please remember to mark the replies as answers if they help.,

    NEDIMMEHIC.ORG


    • Edited by Nedim Mehic Tuesday, October 17, 2017 12:42 PM
    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 12:42 PM
  • So how can I change those fields within powershell?

    In the header of the CSV.


    \_(ツ)_/

    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 1:01 PM
  • Use a computed select statement.

    Import-Csv file | select ... @{'GivenName';e={$_.Firstname}}

    Do the same for all fields you want to rename.


    \_(ツ)_/

    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 1:12 PM
  • Agree with jrv,

    Use provided example for all fields that you need to rename and use |gm to see what value you need to specify if you don't know exact name

    Something like this 

    Import-Csv <path to csv> | select *, @{n='samAccountName';e={$_.LoginName}},
    >> @{n='Name';e={$_.LoginName}},
    >> @{n='GivenName';e={$_.FirstName}},
    >> @{n='SurName';e={$_.LastName}} | New-ADUser -Path "path here"
    


    Please remember to mark the replies as answers if they help.,

    NEDIMMEHIC.ORG

    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 1:17 PM

All replies

  • Hi,

    Everytime when you need to know something about the object pipe it to a gm.

    Get-aduser -filter * | gm

    Do you see first and the last name there and same is for login name? First name is the Givenname and the last name is the Surname so that needs to be changed and samaccountname is the login name. You have to have samaccountname.  You can change them in csv file but it is better that you use hashtable for it. 


    Please remember to mark the replies as answers if they help.,

    NEDIMMEHIC.ORG


    • Edited by Nedim Mehic Tuesday, October 17, 2017 12:42 PM
    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 12:42 PM
  • So how can I change those fields within powershell?
    Tuesday, October 17, 2017 12:54 PM
  • So how can I change those fields within powershell?

    In the header of the CSV.


    \_(ツ)_/

    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 1:01 PM
  • How can I change it in powershell without editing csv file? 
    Tuesday, October 17, 2017 1:03 PM
  • Use a computed select statement.

    Import-Csv file | select ... @{'GivenName';e={$_.Firstname}}

    Do the same for all fields you want to rename.


    \_(ツ)_/

    • Marked as answer by ZiZU11 Tuesday, October 17, 2017 1:42 PM
    Tuesday, October 17, 2017 1:12 PM