none
Script for create bulk users AD PowerShell RRS feed

  • Question

  • Hello team.

    I need support with a script for create multiple users with powershell on active directory. Attached the command that i used for this job. If is possible, i like to know if i have an error in the sentence. Regards. For this script, i based in the file .csv, but when i tried to execute the script, the powershell console devolved me errors. I work with remote console tool of PowerShell.

    Import-CSV C:\NewUsers.csv | ForEach-Object { New-ADUser -Name $_.Name -FirstName $_.FirstName -LastName $_.LastName -Office $_.Office -Title $_.Title -Description $_.Description -Department $_.Department -Company $_.Company  -City $_.City -StateOrProvince $_.State -UserPassword $_.UserPassword -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -DisplayName $_.DisplayName -Country $_.Country -ParentContaine$_.ParentContainer }

    Regards.

    • Moved by Bill_Stewart Monday, May 2, 2016 6:03 PM This is not "scripts on demand"
    Thursday, March 3, 2016 5:23 PM

Answers

  • Hello friends.

    Finally, i developed a script to perform the task of creating massively users without having installed on my server the Active Quest module. This module (Active Quest) requires that you have installed NetFramework and that your server is updated, because if you did not have updated, probably show an error in the installation of NetFramework.

    I attached the script.

    Import-Csv .\users.csv | foreach-object { 
    $userprinicpalname = $_.SamAccountName + "@yourdomain.com" 
    New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.GivenName -SurName $_.SurName -Title $_.Title -Manager $_.Manager -Company $_.Company -Department $_.Department -Path "OU=Masive Users, DC=domain,DC=com" -AccountPassword (ConvertTo-SecureString "WriteYourPasswordforAllAccounts" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru -Description $_.Description -Country $_.Country -EmailAddress $_.Mail }

    To upload users need to create a file in excel and pass it to csv.
    The following structure.

    userPrincipalName	SamAccountName	Name	GivenName	SurName	Title	Department	Company	HomePhone	Manager 	Description	Country	Mail
    

    Each parameter is a column. After exported to csv format and opens through notepad, click Edit, replace, type a semicolon and comma replaced. Ready.

    Now we turn to the server, copy the csv in C: /, open and execute PowerShell script.

    Thursday, July 21, 2016 7:03 AM

All replies

  • Hi,

    Please use the 'Insert Code Block' button to post your code. Also, we'll need the complete error message and a sampling of your input CSV file.

    Are you sure you have zero blanks in your input file?


    EDIT: You're trying to use at least one invalid parameter. See the list here for what you can use:

    http://ss64.com/ps/new-aduser.html


    Thursday, March 3, 2016 5:25 PM
  • Hi.

    Sure. I checked this point with the spaces blank, but i can't find anything.

    This is the line command on the script.

    Import-CSV C:\Test2.csv | ForEach-Object { New-QADUser -Name $_.Name -FirstName $_.FirstName -LastName $_.LastName -Office $_.Office -Title $_.Title -Description $_.Description -Department $_.Department -Company $_.Company  -City $_.City -StateOrProvince $_.State -UserPassword $_.UserPassword -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -DisplayName $_.DisplayName -ParentContainer $_.ParentContainer }

    This is the information in the .csv file.

    ParentContainer,Name,FirstName,LastName,Office,Title,Description,Department ,Company,City,State,UserPassword,SamAccountName,UserPrincipalName,DisplayName,,,
    test.com/TEST/Users/,Monica Linares,Monica,Linares,TEST1,Manager,Manager,IT,IT,,,IT2016,ML4356,monica.linares@test.com,Monica Linares,,,
    test.com/TEST/Users/,Marcela Cruz,Marcela,Cruz,TEST1,Manager,Manager,IT,IT,,,IT2016,MC1233,marcela.cruz@test.com,Monica Linares,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,,,
    

    Regards.

    This is the line command on the script.
    This is the line command on the script.
    This is the line command on the script.
    This is the line command on the script.
    Thursday, March 3, 2016 10:09 PM
  • You have many lines that are full of blanks.  You cannot have any blanks.

    \_(ツ)_/

    Thursday, March 3, 2016 10:21 PM
  • ok, thanks for the point. I checked again, but this spaces are generated when i convert the file excel to .csv. I proceded to erase those space and then run the scrip, but the console give me the error.
    Thursday, March 3, 2016 11:13 PM
  • What error?  We cannot see your screen.

    \_(ツ)_/

    Thursday, March 3, 2016 11:14 PM
  • The error said: 

    Cannot found the parameter that match with parameter FirstName.
    ("Path of the script") 
    Invalid Argument : (:) [New-ADUser ], ParameterBindingException

    Thursday, March 3, 2016 11:21 PM
  • You need to create a new csv
    What i think is that you are having errors because of the blanks like JRV says
    if this is not the case please paste the error
    Regards
    Thursday, March 3, 2016 11:22 PM
  • You still have blank fields in your CSV.  You cannot have blank fields. 

    \_(ツ)_/

    Thursday, March 3, 2016 11:27 PM
  • New-ADUser : No se encuentra ningún parámetro que coincida con el nombre del parámetro 'FirstName'.
    En C:\AD-Users.ps1: 1 Carácter: 72
    + Import-Csv C:\NewUsers.csv | ForEach-Object { New-ADUser -Name $_.Name -FirstNam ...
    +                                                                        ~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-ADUser], ParameterBindingException
        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADUser

    In this moment cannot upload any screen.

    Thursday, March 3, 2016 11:28 PM
  • Im assuming you are loading the Quest cmdlets before running the script
    Right?
    Thursday, March 3, 2016 11:29 PM
  • The parameter -FirstName doesnt exist for New-ADUser
    Thursday, March 3, 2016 11:31 PM
  • Umm , interesting question , I have no knowledge about those Quest cmdlets. Can you explain this point ?. I have tried to remove this attribute , but both the command and the information in file .csv , but the error said again that has another attribute that is not recognized or not match. Any suggestions?

    Also, comment that i work on a station remote of powershell. The version of the powershell on the server is 2.0. The version on my remote console is 4.0.

    Thursday, March 3, 2016 11:40 PM
  • I have all permissions for create, i tested this point successfuly.
    Thursday, March 3, 2016 11:42 PM
  • In post #3 you use New-QADUser which is part of the Quest AD Module 
    You have to download and install that and then inside powershell add the snapin
    Add-PSSnapin quest.activeroles.admanagement
    Then you can use New-QADUser which has -FirstName as a parameter and all the others parameters included in your script
    Regards
    Friday, March 4, 2016 1:46 AM
  • I highly recommend against using the Quest tools. They're outdated and very rarely needed.

    Friday, March 4, 2016 4:27 AM
  • Thank you very much for the contribuition. I will try what you suggest and i comment later.
    Friday, March 4, 2016 5:14 PM
  • Hello friends.

    Finally, i developed a script to perform the task of creating massively users without having installed on my server the Active Quest module. This module (Active Quest) requires that you have installed NetFramework and that your server is updated, because if you did not have updated, probably show an error in the installation of NetFramework.

    I attached the script.

    Import-Csv .\users.csv | foreach-object { 
    $userprinicpalname = $_.SamAccountName + "@yourdomain.com" 
    New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.GivenName -SurName $_.SurName -Title $_.Title -Manager $_.Manager -Company $_.Company -Department $_.Department -Path "OU=Masive Users, DC=domain,DC=com" -AccountPassword (ConvertTo-SecureString "WriteYourPasswordforAllAccounts" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru -Description $_.Description -Country $_.Country -EmailAddress $_.Mail }

    To upload users need to create a file in excel and pass it to csv.
    The following structure.

    userPrincipalName	SamAccountName	Name	GivenName	SurName	Title	Department	Company	HomePhone	Manager 	Description	Country	Mail
    

    Each parameter is a column. After exported to csv format and opens through notepad, click Edit, replace, type a semicolon and comma replaced. Ready.

    Now we turn to the server, copy the csv in C: /, open and execute PowerShell script.

    Thursday, July 21, 2016 7:03 AM
  • Just to help you understand some basic Powershell:

    Import-Csv .\users.csv -Delimiter ','

    This will import CSV without editing the file.

    The issue was, as I posted more than once, a badly formed CSV file.


    \_(ツ)_/

    Thursday, July 21, 2016 10:59 AM