locked
Need to create 22 accounts RRS feed

  • Question

  • I need to create 22 accounts and instead of doing each on maually I was wondering if I could write a short script?

    The accounts are general with the login name changing by one character, the password is going to be the same for all of them.

    They will be created in a 2k8 r2 DC if that helps.

    Wednesday, December 28, 2011 3:15 PM

Answers

  • In addition to the previous suggestions, you can modify my script on http://unlockpowershell.wordpress.com/2010/10/12/creating-random-users-for-a-domain/

    Karl


    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    • Edited by Just Karl Wednesday, December 28, 2011 3:49 PM
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:10 PM
    Wednesday, December 28, 2011 3:49 PM
  • Quest makes some cool add ins for powershell. Check out http://computerperformance.co.uk/powershell/powershell_qad_import_csv.htm

    1. Download, then install the QAD Snap-ins from this site:
      http://www.quest.com/activeroles-server/arms.aspx
    2. Register the snap-in. (Key point)
      add-PSSnapin quest.activeroles.admanagement

    # PowerShell script create users in a named OU
    # Author: Guy Thomas
    # Version 2.4 August 2008 tested on PowerShell v 1.0

    $OuBorn = 'OU=PowerShell,DC=cp2,DC=mosel'
    $Freshmen = 'E:\powershell\QAD\bunch4.csv'
    import-csv $Freshmen |`
    where {new-QADUser -ParentContainer $OuBorn `
    -name $_.name -sAMAccountName $_.sAMAccountName `
    ; enable-QADUser $_.name }

    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:10 PM
    Wednesday, December 28, 2011 3:23 PM
  • If you have 2008R2, you have access to the AD modules.

    You can use this code:

     

    Import-Module activedirectory -ErrorAction silentlycontinue
    for ($i = 1; $i -le 22; $i ++) {
        New-ADUser User$i -Path "ou=test2,dc=contoso,dc=internal"
        Set-ADAccountPassword -Identity User$i -Reset `
             -NewPassword  (ConvertTo-SecureString -AsPlainText "p@ssw0rd" -Force)
        } # end for
    

     


    ([string](0..9|%{[char][int](32+("39826578846355658268").substring(($_*2),2))})).replace(' ','')

    What's new in Powershell 3.0 (Technet Wiki)


    • Edited by Bigteddy Wednesday, December 28, 2011 5:26 PM
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:11 PM
    Wednesday, December 28, 2011 5:25 PM
  • Here is another way with the for command.

     

    FOR /L %%i in (1,1,22) DO ( 
    	dsadd user "cn=Test User%%i,ou=Test Users,ou=Test,dc=contoso,dc=com" ^
    	-samid testuser%%i ^
    	-upn testuser%%i@contoso.com ^
    	-fn Test -ln User%%i ^
    	-display "Test User%%i" ^
    	-pwd P@ssw0rd -disabled no
    )


    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:11 PM
    Wednesday, December 28, 2011 5:25 PM

All replies

  • Quest makes some cool add ins for powershell. Check out http://computerperformance.co.uk/powershell/powershell_qad_import_csv.htm

    1. Download, then install the QAD Snap-ins from this site:
      http://www.quest.com/activeroles-server/arms.aspx
    2. Register the snap-in. (Key point)
      add-PSSnapin quest.activeroles.admanagement

    # PowerShell script create users in a named OU
    # Author: Guy Thomas
    # Version 2.4 August 2008 tested on PowerShell v 1.0

    $OuBorn = 'OU=PowerShell,DC=cp2,DC=mosel'
    $Freshmen = 'E:\powershell\QAD\bunch4.csv'
    import-csv $Freshmen |`
    where {new-QADUser -ParentContainer $OuBorn `
    -name $_.name -sAMAccountName $_.sAMAccountName `
    ; enable-QADUser $_.name }

    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:10 PM
    Wednesday, December 28, 2011 3:23 PM
  • A VBScript example to create 100 users in the default cn=Users container, showing the minimum required:

     

    Option Explicit
    Dim objRootDSE, objContainer, i, objUser, strPassword

    ' Specify password.
    strPassword = "xYz$123k"

    Set objRootDSE = GetObject("LDAP://rootDSE")

    Set objContainer = GetObject("LDAP://cn=Users," & _
        objRootDSE.Get("defaultNamingContext"))

    For i = 1 To 100
        Set objUser = objContainer.Create("User", "cn=UserNo" & i)
        objUser.Put "sAMAccountName", "UserNo" & i
        objUser.SetInfo
        objUser.SetPassword strPassword
    Next

    WScript.Echo "100 Users created."

    -----

     This example assigns the same value for the cn (Common Name) and sAMAccountName (pre-Windows 2000 logon names) of the users, both mandatory attributes. You could also assign values to sn (last name), givenName (first name), displayName, description, etc., all optional. This example also leaves the accounts disabled. You could enable the accounts, and also expire the password so it must be changed at first logon, by adding the following in the For loop:

     

    For i = 1 To 100
        Set objUser = objContainer.Create("User", "cn=UserNo" & i)
        objUser.Put "sAMAccountName", "UserNo" & i
        objUser.SetInfo
        objUser.SetPassword strPassword
        objUser.AccountDisabled = False
        objUser.pwdLastSet = 0
        objUser.SetInfo
    Next

    -----

     


    Richard Mueller - MVP Directory Services
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Edited by Richard MuellerMVP Saturday, December 31, 2011 11:53 AM typo
    Wednesday, December 28, 2011 3:45 PM
  • In addition to the previous suggestions, you can modify my script on http://unlockpowershell.wordpress.com/2010/10/12/creating-random-users-for-a-domain/

    Karl


    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    • Edited by Just Karl Wednesday, December 28, 2011 3:49 PM
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:10 PM
    Wednesday, December 28, 2011 3:49 PM
  • So many ways!  If only all admin tasks were this easy!


    ([string](0..9|%{[char][int](32+("39826578846355658268").substring(($_*2),2))})).replace(' ','')

    What's new in Powershell 3.0 (Technet Wiki)

    Wednesday, December 28, 2011 3:57 PM
  • If you have 2008R2, you have access to the AD modules.

    You can use this code:

     

    Import-Module activedirectory -ErrorAction silentlycontinue
    for ($i = 1; $i -le 22; $i ++) {
        New-ADUser User$i -Path "ou=test2,dc=contoso,dc=internal"
        Set-ADAccountPassword -Identity User$i -Reset `
             -NewPassword  (ConvertTo-SecureString -AsPlainText "p@ssw0rd" -Force)
        } # end for
    

     


    ([string](0..9|%{[char][int](32+("39826578846355658268").substring(($_*2),2))})).replace(' ','')

    What's new in Powershell 3.0 (Technet Wiki)


    • Edited by Bigteddy Wednesday, December 28, 2011 5:26 PM
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:11 PM
    Wednesday, December 28, 2011 5:25 PM
  • Here is another way with the for command.

     

    FOR /L %%i in (1,1,22) DO ( 
    	dsadd user "cn=Test User%%i,ou=Test Users,ou=Test,dc=contoso,dc=com" ^
    	-samid testuser%%i ^
    	-upn testuser%%i@contoso.com ^
    	-fn Test -ln User%%i ^
    	-display "Test User%%i" ^
    	-pwd P@ssw0rd -disabled no
    )


    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:11 PM
    Wednesday, December 28, 2011 5:25 PM
  • Richard Prescott has a nice download in the script repository that can do this in a quick batch using import from csv. here is the link to his project http://gallery.technet.microsoft.com/New-User-Creation-tool-14fa73cd
    Network+,Security+,NCSA,MCTS,MCPS,And MCITP
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:11 PM
    • Unmarked as answer by Skipp2 Tuesday, January 17, 2012 10:43 PM
    Thursday, December 29, 2011 7:37 AM
  • Richard Prescott has a nice download in the script repository that can do this in a quick batch using import from csv. here is the link to his project http://gallery.technet.microsoft.com/New-User-Creation-tool-14fa73cd
    Network+,Security+,NCSA,MCTS,MCPS,And MCITP
    Thanks for the referral!  The link is to a PowerShell GUI that allows you to use a pre-created CSV to create AD accounts using the 2008 R2 AD module.

    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP

    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool 2.0
    AD User Creation tool
    Thursday, December 29, 2011 9:14 PM
  • Again from the command prompt

    FOR /L %i in (1,1,22) DO  net user User%i  ALLUSERPASSWORD  /add /domain

     

    or with a batch

    ::--start batch create-usr.cmd

    @echo off
    FOR /L %%i in (1,1,22) DO  net user User%%i ALLUSERPASSWORD /add /domain

    ::-- end batch


    Gastone Canali >http://www.armadillo.it
    • Proposed as answer by Just Karl Friday, December 30, 2011 8:08 PM
    • Marked as answer by Richard MuellerMVP Tuesday, January 3, 2012 3:12 PM
    • Unmarked as answer by Skipp2 Tuesday, January 17, 2012 10:43 PM
    Thursday, December 29, 2011 11:00 PM
  • There are 7 good answers here. Want to pick one? =^)
    Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
    Saturday, December 31, 2011 7:52 AM
  • "Melius abundare quam deficere" "Better more than less" ;)

    Thank you and Good Year to all


    Gastone Canali >http://www.armadillo.it
    Saturday, December 31, 2011 5:27 PM
  • "Melius abundare quam deficere" "Better more than less" ;)

    Thank you and Good Year to all


    Gastone Canali >http://www.armadillo.it

    Well, as Ed says, pick one!
    ([string](0..9|%{[char][int](32+("39826578846355658268").substring(($_*2),2))})).replace(' ','')

    What's new in Powershell 3.0 (Technet Wiki)

    Sunday, January 1, 2012 6:00 AM
  • Thanks for all the suggestions.  I will try them out.
    Monday, January 9, 2012 3:42 PM
  • I am having some issues with this method.

    I have cleared out the example info and replaced it with my info, but when I hit submit it says successful, but there is errors on the cmd window.

    Not sure where the problem lies as I am new to powershell.

    Thursday, January 12, 2012 3:18 PM
  • Skipp2, there have been about 10 suggestions for your problem.  Which code are you using?  Please post the code and the errors you are getting.
    Grant Ward

    What's new in Powershell 3.0 (Technet Wiki)

    Thursday, January 12, 2012 3:22 PM
  • Doh!

    I was referring to Rich Prescott's


    Thursday, January 12, 2012 9:56 PM
  • Doh!

    I was referring to Rich Prescott's



    What does Doh mean?

    Post you script and error messages.  Just saying it doesn't work is not very helpful.

     


    jv
    Thursday, January 12, 2012 11:20 PM
  • Doh!

    I was referring to Rich Prescott's



    What does Doh mean?

    Post you script and error messages.  Just saying it doesn't work is not very helpful.

     


    jv

    http://www.merriam-webster.com/dictionary/doh

     

    Here is the error

    Friday, January 13, 2012 6:53 PM
  • This isn't going well, is it?
    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script
    Friday, January 13, 2012 7:14 PM
  • Doh!

    I was referring to Rich Prescott's



    What does Doh mean?

    Post you script and error messages.  Just saying it doesn't work is not very helpful.

     


    jv

    http://www.merriam-webster.com/dictionary/doh

     

    Here is the error


    The graphic is completely unreadable even at 1152 pixels.  The compression jsut makes it a blur and I can only read it if I zoom it 150%.

    I did not knwo the doh was a real word.  It is valspeak and cane in via Hollywood comedies about how dumb Valley Girls were.  They would always say 'doh' - meaning wow! or 'cool'  I think.  I jsu have never seen it used outside of Twitter or on an old tv movie.

    See - I learn something every day.

     

     


    jv
    Friday, January 13, 2012 7:30 PM
  • This isn't going well, is it?
    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script


    No - I think it is answered.

    The error message is clear as mud. Can you read it?

    This is what it looks like when I get it.  Can anyone really read this?

    Evetualy we can see that it says 'cannot validate parameter on 'Path'.  WHich says there is junk being fed in from the file.


    jv
    Friday, January 13, 2012 7:54 PM
  • I thought Homer Simpson invented the word 'doh'.
    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script
    Saturday, January 14, 2012 5:19 AM
  • I thought Homer Simpson invented the word 'doh'.
    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script


    I am sure t was invented by Moon Zappa in the early 80s

     


    jv
    Saturday, January 14, 2012 8:52 AM
  • So what do I need to do to fix this.
    Tuesday, January 17, 2012 6:28 PM
  • Hi,

    What do you need to do to fix what? This question is marked answered already.

    Bill

    Tuesday, January 17, 2012 6:49 PM
  • Hi,

    What do you need to do to fix what? This question is marked answered already.

    Bill

    It was marked as answered before I posted the error msg.
    Tuesday, January 17, 2012 10:42 PM
  • Hi,

    What do you need to do to fix what? This question is marked answered already.

    Bill

    It was marked as answered before I posted the error msg.


    I think the consensus was that noone can read your error message and we are not quite sure what code you used to generate it.

     

     

     


    jv
    Tuesday, January 17, 2012 10:51 PM