Create Lab AD (continue)

In my last post I did show you how to take names
from the internet to make “real” names.

I know that these are Swedish names and I will post
2 similar functions with US names later on.

Now when we have the names we want to make
usernames (samAccountName) of them as well.

So, first of all we need to clean the names from special
characters and other letter that we don’t want to use.
(All of the –creplace should be on the same line)

$userFirstName = $firstName -creplace('å','a')
-creplace('ä','a') -creplace('ö','o')
-creplace('Å','A') -creplace('Ä','A')
-creplace('Ö','O')  -creplace('ü','u')
-creplace('Ü','U') -creplace('é','e')
-creplace('É','E')

And then we want to only use lower letters.

$userFirstName = $userFirstName.ToLower()

And then we want to take the first 2 letters in the first name.

$userShortFirstName = $userFirstName.Substring(0,2)

For the last name we will do the same thing.

$userLastName = $lastName -creplace(å,a)

-creplace(ä,a)   -creplace(ö,o)

-creplace(Å,A-creplace(Ä,A)

-creplace(Ö,O-creplace(ü,u)

-creplace(Ü,U-creplace(é,e)

-creplace(É,E)

$userLastName = $userLastName.ToLower()

$userShortLastName = $userLastName.Substring(0,$lettersUNamelName)

And we like to be able to create lots of accounts so we need to add
numbers to our samAccountNames.

So we do like this

$userNumber = Get-Random -Minimum 10000 -Maximum 99999

And then we put It all together like this

$userSAM = $userShortFirstName + $userShortLastName + $userNumber
    

The output of this will be something like

frwa12997
asv34432
teol98231

If you want more possible users, then you can higher the
-Maximum number. And if you want less numbers you can lower
the –Minimum and –Maximum numbers.

 
 

No related posts.

This entry was posted in PowerShell Blogs and tagged , , . Bookmark the permalink.

0 Responses to Create Lab AD (continue)

  1. bsonposh says:

    RT @walle75: Next step to create a lab AD with #PowerShell #How-To, http://bit.ly/8fN5o1 <= my version http://is.gd/5qtGq

  2. Fredrik Wall says:

    Next step to create a lab AD with #PowerShell #How-To, http://bit.ly/8fN5o1

  3. Neptune says:

    The dots, rings, umlaut and hats etc. are collectively known as diacritics. If you in Powershell want to remove these to go get the base latin letter you can use a function I’ve written. It will convert ä and å to a and also characters such as the Portuguese ç to the latin basic chacter c.

    Check my Convert-DiacriticCharacters function on my blogg:

    http://blogg.idg.se/identitetsproblem/entry.jsp?messid=12316

    Found your blog thanks to Predrag… :)

  4. Fredrik Wall says:

    Cool function, thanks for the tip!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>