Last active
May 17, 2016 12:56
-
-
Save Xainey/541d433a6c383d3949f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Concept Based Off Faker: https://github.com/fzaninotto/Faker | |
function Random-Name | |
{ | |
[CmdletBinding()] | |
[OutputType([System.Double])] | |
param | |
( | |
[parameter(Mandatory = $false)] | |
[ValidateSet('male', 'female')] | |
[string] $Gender = 'male' | |
) | |
$firstNameMale = ( | |
'Aaron', 'Abdiel', 'Abdul', 'Abdullah', 'Abe', 'Abel', 'Abelardo', 'Abner', | |
'Abraham', 'Adalberto', 'Adam', 'Adan' | |
) | |
$firstNameFemale = ( | |
'Aaliyah', 'Abagail', 'Abbey', 'Abbie', 'Abbigail', 'Abby', 'Abigail', | |
'Abigale', 'Abigayle', 'Ada', 'Adah', 'Adaline', 'Addie', 'Addison', 'Adela' | |
) | |
$lastName = ( | |
'Abbott', 'Abernathy', 'Abshire', 'Adams', 'Altenwerth', 'Anderson', 'Ankunding', | |
'Armstrong', 'Auer', 'Aufderhar', 'Bahringer', 'Bailey', 'Balistreri', 'Barrows' | |
) | |
$titleMale = ( | |
'Mr.', 'Dr.' | |
) | |
$titleFemale = ( | |
'Mrs.', 'Ms.', 'Miss', 'Dr.' | |
) | |
$suffix = ( | |
'Jr.', 'Sr.', 'I', 'II', 'III', 'IV', 'V', 'MD', 'DDS', 'PhD', 'DVM' | |
) | |
$maleNameFormats = ( | |
'{{firstNameMale}} {{lastName}}', | |
'{{titleMale}} {{firstNameMale}} {{lastName}}', | |
'{{firstNameMale}} {{lastName}} {{suffix}}', | |
'{{titleMale}} {{firstNameMale}} {{lastName}} {{suffix}}' | |
) | |
$femaleNameFormats = ( | |
'{{firstNameFemale}} {{lastName}}', | |
'{{titleFemale}} {{firstNameFemale}} {{lastName}}', | |
'{{firstNameFemale}} {{lastName}} {{suffix}}', | |
'{{titleFemale}} {{firstNameFemale}} {{lastName}} {{suffix}}' | |
) | |
function Get-RandomPart | |
{ | |
[CmdletBinding()] | |
[OutputType([System.String])] | |
param | |
( | |
[parameter(Mandatory = $true)] | |
[System.Array] $part | |
) | |
return $part[(Get-Random -Maximum ([array]$part).count)] | |
} | |
if($gender.Equals("male")) | |
{ | |
$format = Get-RandomPart -part $maleNameFormats | |
} | |
else | |
{ | |
$format = Get-RandomPart -part $femaleNameFormats | |
} | |
$vars = [ordered]@{} | |
$regex = [regex]"{{\s?([^}]*)\s?}}" | |
foreach($match in $regex.Matches($format)) | |
{ | |
if($match.Length -ile 0) | |
{ | |
continue | |
} | |
$value = $match.groups[1].value | |
$vars[$value] = Get-RandomPart -part (Get-Variable -Name ` | |
(Get-Variable -Name 'value' -ValueOnly) -ValueOnly) | |
} | |
return $vars.values -join ' ' | |
} | |
cls | |
Random-Name -Gender male | |
Random-Name -Gender female |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment