I wrote a script some years back in VBScript that made
Active Directory Users with “Real Swedish” names.
It’s took Firstname from one text file and Lastname from
another text file, randomly. And made random Passwords as well.
So instead of getting users like “user0001” and “user998” I got
”Anders Svensson” and “Lena Persson”. Prettys nice.
The bad part about the VBScript was that It took 10-15 min to clean
the textfiles first.
I’m a computer geek and I do lots of labs with AD so I wanted to
make a similar thing with PowerShell.
After some work I have made 2 functions that will get two
lists of common First and Last names from The Gothenburg University.
The first function are:
function getFNames { # Get a list of Swedish Firstnames from Gothenburg University param ($fNameFile) if(!(test-path -path $fNameFile)){ if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient } $url="http://spraakbanken.gu.se/statistik/lbfnamn.phtml" $fNames = $WebClient.DownloadString($url) -replace "[0-9]","" -replace "<td>",""
-replace "<tr>","" -replace "</td>","" -replace "</tr>","" -replace "<b>",""
-replace "</b>","" -replace "<td class=""le"">","" -replace "<table>",""
-replace "</table>","" -replace "<br />","" -replace "<hr />",""
-replace "<body>","" -replace "</body>","" -replace "<html>",""
-replace "</html>","" -replace "<table width=""%""><td width=""%"">",""
-replace "<td class=""lastupd"">Senaste ändring <b class=""date""> okt av lbtekn@svenska.gu.se</a>.",""
-replace "<!doctype html public ""-//wc//dtd html . transitional//en"">",""
-replace "<head>","" -replace "</head>","" -replace "<h>","" -replace "</h>",""
-replace "<title>","" -replace "</title>","" -replace "<tr class=""headrow"">",""
-replace " <meta http-equiv=""Content-Type"" content=""text/html; charset=iso—"">",""
-replace " <link rel=""STYLESHEET"" href=""/css/statistik.css"" type=""text/css"">",""
-replace "Vanliga förnamn, ordnade efter frekvens.",""
-replace " Rang Pojknamn Frekvens Rang Flicknamn Frekvens",""
-replace "\s{3,}", " "
$fNames = $fNames -split (" ") foreach ($fName in $fNames) { $fName | Out-File $fNameFile -append } } }
You will call It like this:$fNameFile = "c:\scripts\fname.txt"getFNames $fNameFile
or simply
getFNames 'c:\scripts\fname.txt'
First of all It will look for the file with all the first names.
If It can’t find It, It will download It from the server at
Gothenburg University and clean It.
Now You Got a text file with lots of names (1000).
And the other function are:
function getLNames { # Get a list of Swedish Lastnames from Gothenburg University param ($lNameFile) if(!(test-path -path $lNameFile)){ if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient } $url="http://spraakbanken.gu.se/statistik/lbenamn.phtml" $lNames = $WebClient.DownloadString($url) -replace "[0-9]","" -replace "<td>",""
-replace "<tr>","" -replace "</td>","" -replace "</tr>","" -replace "<b>",""
-replace "</b>","" -replace "<td class=""le"">","" -replace "<table>",""
-replace "</table>","" -replace "<br />","" -replace "<hr />","" -replace "<body>",""
-replace "</body>","" -replace "<html>","" -replace "</html>",""
-replace "<table width=""%""><td width=""%"">",""
-replace "<td class=""lastupd"">Senaste ändring <b class=""date""> okt av lbtekn@svenska.gu.se</a>.",""
-replace "<!doctype html public ""-//wc//dtd html . transitional//en"">",""
-replace "<head>","" -replace "</head>","" -replace "<h>","" -replace "</h>",""
-replace "<title>","" -replace "</title>","" -replace "<tr class=""headrow"">",""
-replace " <meta http-equiv=""Content-Type"" content=""text/html; charset=iso—"">",""
-replace " <link rel=""STYLESHEET"" href=""/css/statistik.css"" type=""text/css"">",""
-replace "Vanliga förnamn, ordnade efter frekvens.",""
-replace " Rang Pojknamn Frekvens Rang Flicknamn Frekvens",""
-replace "\s{3,}", " "
-replace " efternamn,frekvensordning Vanliga efternamn, i frekvensordning Rang Namn Frekvens ",""
$lNames = $lNames -split (" ") foreach ($lName in $lNames) { $lName | Out-File $lNameFile -append } } }
And this one will give you the same as the other function.
You will call It like this:$lNameFile = "c:\scripts\lname.txt"getLNames $lNameFile
or simply
getLNames 'c:\scripts\lname.txt'
Now you got 1000 first names and 1000 last names to make random names of.
$firstName = Get-Content $fNameFile | Get-Random -ErrorAction SilentlyContinue $lastName = Get-Content $lNameFile | Get-Random -ErrorAction SilentlyContinue
$firstName + “ “ + $lastName
I will post more of my script tommorow. This was todays function gift from me
No related posts.
2 functions to create "real" names, http://bit.ly/5hMhNj #PowerShell
Nice work dalle!
Thanks!
I hope that you will like the rest of my post regarding to setup a Lab AD. They will be posted every day from now on.
It’s pretty nice to create a new lab AD with “real” names, OUs, addresses etc in 2 min or so
And the script can be applyed to other tasks as well.
Pingback: Create Lab AD – Updated version | Dalle & DXter