Function Get-RandomNames{
[CmdletBinding()]
[OutputType([Object])]
param(
[Parameter(Mandatory=$false)]
[int] $count=10
)
$Webfemale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-female-first.txt"
$Webmale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-male-first.txt"
$WebSurname = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-surnames.txt"
$female = @()
$female = $Webfemale.Content.Split("`n").Trim() | ?{$_.length -gt 2}
$male = @()
$male = $Webmale.Content.Split("`n").Trim() | ?{$_.length -gt 2}
$Surname = @()
$Surname = $WebSurname.Content.Split("`n").Trim() | ?{$_.length -gt 2}
$names = @()
for($i=0; $i -ne $count; $i++)
{
if(($i % 2) -eq 1)
{
$names += New-Object PSObject -Property @{Given=$($male | Get-Random);
Middle=$($male | Get-Random);
Surname=$($Surname | Get-Random)}
}
else
{
$names += New-Object PSObject -Property @{Given=$($female | Get-Random);
Middle=$($female | Get-Random);
Surname=$($Surname | Get-Random)}
}
}
Return $names
}
Pulls a list of all popular male and female names from the last 50 years and the 500 most common last names, and combines them to create a PowerShell object with a list of randomly generated names.
PS C:\> Function Get-RandomNames{
>> [CmdletBinding()]
>> [OutputType([Object])]
>> param(
>> [Parameter(Mandatory=$false)]
>> [int] $count=10
>> )
>> $Webfemale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-female-first.txt"
>> $Webmale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-male-first.txt"
>> $WebSurname = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-surnames.txt"
>> $female = @()
>> $female = $Webfemale.Content.Split("`n").Trim() | ?{$_.length -gt 2}
>> $male = @()
>> $male = $Webmale.Content.Split("`n").Trim() | ?{$_.length -gt 2}
>> $Surname = @()
>> $Surname = $WebSurname.Content.Split("`n").Trim() | ?{$_.length -gt 2}
>> $names = @()
>> for($i=0; $i -ne $count; $i++)
>> {
>> if(($i % 2) -eq 1)
>> {
>> $names += New-Object PSObject -Property @{Given=$($male | Get-Random);
>> Middle=$($male | Get-Random);
>> Surname=$($Surname | Get-Random)}
>> }
>> else
>> {
>> $names += New-Object PSObject -Property @{Given=$($female | Get-Random);
>> Middle=$($female | Get-Random);
>> Surname=$($Surname | Get-Random)}
>> }
>> }
>> Return $names
>> }
>> Get-RandomNames
Given Middle Surname
----- ------ -------
Sofia Renee Luna
Douglas Camden Klein
Tara Kristi Frazier
Johnny Cory Floyd
Lucy Kendra Sullivan
Colby Chase Holmes
Nora Shelly Hansen
Blake Shannon Williams
Holly Penelope Mitchell
Grayson Ezra Hampton