Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HELP ! Urgent  Mass Account Creation in a Domain within a specific OU

Posted on 2016-10-17
6
Medium Priority
?
94 Views
Last Modified: 2016-10-28
Hello,

I need a powershel Script for a mass user account creation.
Below are the specification


1- Account will be created in a Domain within a specific OU
Path = OU=Test,OU=Users,DC=Genactic,DC=sys

2- The Login accounts should be from
TCA0008000 to TCA0009999

3- First Name = Agency Sales Notebook (Same First Name For all accounts)

4- Last Name = CLL (Same Last Name For all accounts)

5- Email = cll_tca@salesentreprise.net (Same email For all accounts)

6- Passwords = None or any passwords (The account are not inteaded for login purposes)

7- The account should be disabled when created

8- Password Never Expired

9- Account never expired

10- A log file to check the account creation.

I would like to be able to modify the domain, the OU path, the  first and last name and the email in order to run the script for an other domain with different input.

Thank You !
0
Comment
Question by:AMATERASOU
6 Comments
 
LVL 17

Expert Comment

by:Todd Nelson
ID: 41847502
At a basic level, I feel you should start with a CSV file for all your users that you need created.  Something similar to this.  The Name field has to be defined and unique across all accounts, and ideally, the UPN should be defined as well...

Name,UserPrincipalName
TCA0008000,TCA0008000@domain.local
TCA0008001,TCA0008001@domain.local
TCA0008002,TCA0008002@domain.local
TCA0008003,TCA0008003@domain.local

Open in new window



Then, use a script similar to this to create the users with your specified criteria...

Import-Module ActiveDirectory

$MyPassword = Read-Host "Enter Password" -AsSecureString

Import-Csv "C:\Tools\Scripts\MyNewUsers.csv" | ForEach-Object { 

     New-ADUser -Name $_.Name -SamAccountName $_.Name -UserPrincipalName $_.UserPrincipalName -DisplayName "Agency Sales Notebook CLL" -Surname "CLL" -Path "OU=Users,OU=Test,DC=d2,DC=local" -Email "cll_tca@salesentreprise.net" -AccountPassword $MyPassword -PasswordNeverExpires $True -Enabled $False

}

Open in new window



Hope that helps.  Let me know.
0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 41847516
Import-Module ActiveDirectory
$MyPassword = Read-Host 'Enter Password' -AsSecureString
[int] $counter = 8000
do{
$username = 'TCA0000'+ $counter.tostring()
$userprincipalname = $username + '@genactic.sys'
$name = $username
New-ADUser -Name $Name -SamAccountName $username -UserPrincipalName $UserPrincipalName -DisplayName 'Agency Sales Notebook CLL' -Surname 'CLL' -Path 'OU=Test,OU=Users,DC=Genactic,DC=sys' -Email 'cll_tca@salesentreprise.net' -AccountPassword $MyPassword -PasswordNeverExpires $True -Enabled $False -whatif
$counter++
} while ($counter -le 9999)

 

Open in new window

0
 
LVL 9

Expert Comment

by:Antzs
ID: 41847783
Run the below using Exchange power Shell.  Key in all users' details in the attached csv file.

[PS] C:\>Import-CSV "C:\Users\yourpath\Downloads\userlist.csv" | foreach {new-mailbox -Name $_.DisplayName -FirstName $_.Firstname -LastName $_.Lastname -DisplayName $_.DisplayName -Alias $_.alias  -Database $_.Database -password (ConvertTo-SecureString $_.password -AsPlainText -force) -ResetPasswordOnNextLogon $true -UserPrincipalName $_.UPN -OrganizationalUnit $_.OrganizationalUnit}
UserList.csv
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 

Author Comment

by:AMATERASOU
ID: 41848169
Hello ,

But i will like to Log Account creation in an output file with the account names and Status (OK or KO)

David Johnson is the script which feef better


Import-Module ActiveDirectory
$MyPassword = Read-Host 'Enter Password' -AsSecureString
[int] $counter = 8000
do{
$username = 'TCA0000'+ $counter.tostring()
$userprincipalname = $username + '@genactic.sys'
$name = $username
New-ADUser -Name $Name -SamAccountName $username -UserPrincipalName $UserPrincipalName -DisplayName 'Agency Sales Notebook CLL' -Surname 'CLL' -Path 'OU=Test,OU=Users,DC=Genactic,DC=sys' -Email 'cll_tca@salesentreprise.net' -AccountPassword $MyPassword -PasswordNeverExpires $True -Enabled $False -whatif
$counter++
} while ($counter -le 9999)

 

Thank you
0
 
LVL 17

Accepted Solution

by:
Todd Nelson earned 2000 total points
ID: 41848376
I like David's script too. But I had to modify it because it would not have not created the users with the "-WhatIf" parameter present.

Also, I modified to create users TCA0008000 to TCA0009999 (based on your example) instead of TCA00008000 to TCA00009999--with one extra zero.

And I removed the unnecessary $name variable because it is redundant to the $username variable.

I added the GivenName parameter for each users based on your criteria and removed SamAccountName because it is based on the Name parameter and added without specifying explicitly.

Lastly, I added a section that makes the variables easy to locate and update based on whatever environment they need to be changed for.

Therefore, I suppose you want something like this with basic output logged of the values you need set...

Import-Module ActiveDirectory

$MYPASSWORD = Read-Host "Enter Password" -AsSecureString

[int] $counter = 8000

do {

     #SET VARIABLES
     $USERNAME = "TCA000"+ $counter.tostring()
     $USERPRINCIPALNAME = $USERNAME + "@Genactic.sys"
     $DISPLAYNAME = "Agency Sales Notebook CLL"
     $FIRSTNAME = "Agency Sales Notebook"
     $LASTNAME = "CLL"
     $OUPATH = "OU=Test,OU=Users,DC=Genactic,DC=sys"
     $EMAILADDRESS = "cll_tca@salesentreprise.net"

     #CREATE USERS
     New-ADUser -Name $USERNAME -UserPrincipalName $USERPRINCIPALNAME -DisplayName $DISPLAYNAME -GivenName $FIRSTNAME -Surname $LASTNAME -Path $OUPATH -Email $EMAILADDRESS -AccountPassword $MYPASSWORD -PasswordNeverExpires $True -Enabled $False

     #LOG OF CREATED USERS
     Get-ADUser -Identity $USERNAME -Properties EmailAddress,DisplayName,PasswordNeverExpires,Enabled | Select-Object Name,GivenName,Surname,DisplayName,EmailAddress,DistinguishedName,SamAccountName,UserPrincipalName,PasswordNeverExpires,Enabled | Out-file "NewUserResults.txt" -Append

     $counter++

} while ($counter -le 9999)

Open in new window

0
 

Author Closing Comment

by:AMATERASOU
ID: 41863723
thx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question