+ Post New Thread
Results 1 to 10 of 10
Windows Server 2008 R2 Thread, Bulk User Creation using Powershell in Technical; Hello all, I'm trying to create a Powershell script to automate bulk user creation as it becomes a bit of ...
  1. #1

    Join Date
    Nov 2011
    Location
    In the server room... cursing like a madman
    Posts
    32
    Thank Post
    11
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Bulk User Creation using Powershell

    Hello all,

    I'm trying to create a Powershell script to automate bulk user creation as it becomes a bit of a pain with the new intake of students each year. I have found a script online and I have slightly modified it but it doesn't appear to be working in a test environment I have.

    This is the script:

    Code:
    import-module activedirectory
    import-module grouppolicy
    
    $mydom = (get-addomain).distinguishedname
    
    $ouName = "Sales"
    
    $oudn = "OU=$ouName,$mydom"
    
    $userCount = 10
    
    $datetime = get-date -format G
    $desc = "Test user created $datetime"
    
    $OU = get-ADOrganizationalUnit -Filter { name -eq $ouName }
    if($OU -eq $Null)
    {New-ADOrganizationalUnit -Name $OUName -Path $mydom}
    else
    {write-host "The OU" $ou "already exists - this is good..."}
    
    $i = 1
    while ($i -le $userCount)
    {
    $uname = "User" + $i
    $UDdname = "Test User" + $i
    New-ADUser -Name $uname -SamAccountName $uname -DisplayName $UDdname -Path $oudn -Enabled $true -ChangePasswordAtLogon $true -description $desc -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -force) -PassThru
    $i = $i + 1
    }
    And I am getting this error when I attempt to run the script:

    Code:
    New-ADUser : Directory object not found
    At C:\Users\James\Documents\test.ps1:26 char:11
    + New-ADUser <<<<  -Name $uname -SamAccountName $uname -DisplayName $UDdname -Path $oudn -Enabled $t
    AtLogon $true -description $desc -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -f
        + CategoryInfo          : ObjectNotFound: (CN=User10,OU=Sa...gramming,DC=com:String) [New-ADUser
       undException
        + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Comman
    Can anyone point in the direction as to why this isn't working?

    Many thanks.

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Is it actually creating the sales OU? Or any users?

    Can't scroll error very well on phone but looks like it can't find the ou. But wanted to check if it's doing anything or just bombing out at start?

    Steve

  3. #3

    Join Date
    Nov 2011
    Location
    In the server room... cursing like a madman
    Posts
    32
    Thank Post
    11
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    A part of the script is set to look for the OU I want to create users in and it comes back saying that it has been found.

    Code:
    $OU = get-ADOrganizationalUnit -Filter { name -eq $ouName }
    if($OU -eq $Null)
    {New-ADOrganizationalUnit -Name $OUName -Path $mydom}
    else
    {write-host "The OU" $ou "already exists - this is good..."}
    It keeps getting stuck at this part of the script

    Code:
    New-ADUser -Name $uname -SamAccountName $uname -DisplayName $UDdname -Path $oudn -Enabled $true -ChangePasswordAtLogon $true -description $desc -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -force) -PassThru
    If I remove "-Name $uname" it will prompt me to enter User names, which I'm guessing that the script isn't designed to do so (bearing in mind this script originally came from a random blog with comments that it worked).

  4. #4
    jmcdermott's Avatar
    Join Date
    Feb 2008
    Location
    Cornwall
    Posts
    177
    Thank Post
    17
    Thanked 44 Times in 36 Posts
    Rep Power
    21
    Have you considered just using an batch script it is a lot easier than power shell, the command is: net user {username} {password} /add
    You can also add /fullname "firstname surname" if you want more details added.
    Using excel it this is very fast to create, followed by a quick copy and paste to a batch file then run it on the server, use ad to move users to the right ou, selct all of them and change the home path and profile if needed.

    eg. Joe blogs
    net user jblogs Password1 /add /fullname "Joe Blogs"

    If you want a copy of my excel sheet let me know.

  5. #5

    Join Date
    Nov 2011
    Location
    In the server room... cursing like a madman
    Posts
    32
    Thank Post
    11
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by jmcdermott View Post
    Have you considered just using an batch script it is a lot easier than power shell, the command is: net user {username} {password} /add
    You can also add /fullname "firstname surname" if you want more details added.
    Using excel it this is very fast to create, followed by a quick copy and paste to a batch file then run it on the server, use ad to move users to the right ou, selct all of them and change the home path and profile if needed.

    eg. Joe blogs
    net user jblogs Password1 /add /fullname "Joe Blogs"

    If you want a copy of my excel sheet let me know.
    If you could upload your Excel spreadsheet so I can take a gander, that would be brilliant.

    Thanks

  6. #6

  7. Thanks to Arthur from:

    JMBates (11th November 2012)

  8. #7

    Join Date
    Nov 2011
    Location
    In the server room... cursing like a madman
    Posts
    32
    Thank Post
    11
    Thanked 0 Times in 0 Posts
    Rep Power
    0

  9. #8
    Duke5A's Avatar
    Join Date
    Jul 2010
    Posts
    818
    Thank Post
    84
    Thanked 136 Times in 116 Posts
    Blog Entries
    8
    Rep Power
    32
    It looks like the script is complaining that the user object doesn't exist. I use VB for this stuff and you have to create the user before you can set the password or it'll give the exact same error. Try setting the password on a separate line after the user object has been created.

  10. #9
    jmcdermott's Avatar
    Join Date
    Feb 2008
    Location
    Cornwall
    Posts
    177
    Thank Post
    17
    Thanked 44 Times in 36 Posts
    Rep Power
    21
    user creation.xls Here is my file.

  11. Thanks to jmcdermott from:

    JMBates (14th November 2012)

  12. #10
    ADMaster's Avatar
    Join Date
    May 2012
    Posts
    348
    Thank Post
    5
    Thanked 38 Times in 33 Posts
    Rep Power
    25
    I have had this process fully automated, I posted my script here.

    Tech Blog: Add Users Script

    Have a look and see if it will do what you need.

  13. 2 Thanks to ADMaster:

    jamin (16th March 2013), JMBates (14th November 2012)



SHARE:
+ Post New Thread

Similar Threads

  1. Active Directory - Single and Bulk User creation and FREE!!
    By siuko in forum How do you do....it?
    Replies: 39
    Last Post: 20th June 2012, 12:29 PM
  2. Bulk user Creation
    By Jamie_a in forum Windows
    Replies: 10
    Last Post: 14th January 2009, 07:30 PM
  3. bulk user creation
    By jonbones in forum Network and Classroom Management
    Replies: 1
    Last Post: 18th June 2008, 11:43 AM
  4. Bulk User Creation Tools
    By mark in forum Downloads
    Replies: 16
    Last Post: 10th July 2007, 05:24 PM
  5. Bulk user creation
    By Dos_Box in forum How do you do....it?
    Replies: 63
    Last Post: 13th November 2006, 08:02 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •