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 99999And then we put It all together like this
$userSAM = $userShortFirstName + $userShortLastName + $userNumberThe output of this will be something like
frwa12997asv34432teol98231If 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.
RT @walle75: Next step to create a lab AD with #PowerShell #How-To, http://bit.ly/8fN5o1 <= my version http://is.gd/5qtGq
Next step to create a lab AD with #PowerShell #How-To, http://bit.ly/8fN5o1
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…
Cool function, thanks for the tip!