Monday, September 19, 2011

Creating a Domain for Users Random


I needed to create some users of my DS; I created for use in the book "Windows PowerShell Bible" for Chapter Exchange Management.

I could have done something simple like:




001
1..120 | ForEach { Net User “BookUser$_” P@ssW0rd /ADD /Domain}



This would have created 120 users in the Users ou on my domain, but they would have all been “BookUser” users – where’s the variety in that?
I wanted random users, to more closely mimic a real domain. Searching for a random name generator led me to http://www.kleimo.com/random/name.cfm. I chose to create 30 random names for both sexes, and ran the “Generate Random Names”
I copied the 30 resultant names to a notepad, and ran the page two more times, giving me 120 names.
Of those, a few were single names, which I eliminated.
I then replaced each space with a comma, saved the file as a .csv, and opened it in Excel.
Using Excel, I created a user name consisting of the first initial of the first name, and the whole last name.
I then added a 4th column, for the password.
Finally, I added column headers: First, Last, Login, and Password. Once again, I saved the file.
Now, I’m ready for PowerShell:

001
002
003
004
005
006
007
008
009
010
011
012
013
014
$bookOU = [ADSI]“LDAP://OU=Users,OU=Apps,DC=book,DC=local” 
foreach ($user in import-csv users.csv
)
{

$newUser = $bookOU.Create(“user”,“cn=” +$user.login)
$newUser.put(“sn”, $user.Last)
$newUser.put(“DisplayName”, $user.First + ” “ +$user.Last)
$newUser.put(“givenName”, $user.First)
$newUser.put(“sAMAccountName”,$user.login)
$newUser.put(“userPrincipalName”,$user.login + “@book.com”)
$newUser.SetInfo()
$newUser.SetPassword($user.password)
$newUser.put(“userAccountControl”, 512)
$newUser.SetInfo()
}
There you go… 14 lines, and a little work, and I have over 100 users on my domain.

SPONSORS:

No comments:

Post a Comment