Skip to content

Instantly share code, notes, and snippets.

@joegasper
Last active September 2, 2021 04:02
Show Gist options
  • Save joegasper/370dddff12c642a985308f5cbf6ceefa to your computer and use it in GitHub Desktop.
Save joegasper/370dddff12c642a985308f5cbf6ceefa to your computer and use it in GitHub Desktop.
Generate random names and accounts based on Lorem Ipsum
<#
.Synopsis
Return a name based on Lorem Ipsum.
.DESCRIPTION
Calls public Loren Ipsum API and returns name and account name if requested.
.EXAMPLE
Get-LoremName
FirstName LastName
--------- --------
Plane Gloriosam
Return a name.
.EXAMPLE
Get-LoremName -Quantity 4
FirstName LastName
--------- --------
Obrutum Peccata
Inermis Uti
Epicuro Quoddam
Quodam Congruens
Return 4 names.
.EXAMPLE
Get-LoremName -Quantity 2 -WithAccount
FirstName LastName UserName
--------- -------- --------
Vitam Saluto Vitam.Saluto56
Intellegit Hoc Intellegit.Hoc18
Return 2 names with account name.
.INPUTS
Count: Number of names to return
WithAccount: Return an account name.
.NOTES
Release Date: 2019-03-03
Author: JoeGasper@hotmail.com
Inspired to create by: https://twitter.com/MichaelBender/status/1101921078350413825?s=20
#>
function Get-LoremName {
[CmdletBinding(PositionalBinding = $false)]
[Alias()]
[OutputType([String])]
Param
(
# Number of Names to return
[Parameter(
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
ValueFromRemainingArguments = $false,
Position = 0)]
[Alias("Quantity")]
[int]
$Count = 1,
# Include account name
[Parameter()]
[Switch]
$WithAccount
)
Begin {
$loremApi = 'https://loripsum.net/api/5/verylong/plaintext'
$FirstText = 'FirstName'
$LastText = 'LastName'
$AccountText = 'UserName'
$li = (Invoke-RestMethod -Uri $loremApi) -replace "\?|,|-|\.|;|:|\n", '' -split ' ' | ForEach-Object { if ($_.Length -ge 3) {(Get-Culture).TextInfo.ToTitleCase($_)}} | Sort-Object -Unique
$MaxNames = $li.Count - 1
}
Process {
if ($WithAccount) {
for ($i = 0; $i -lt $Count; $i++) {
$First = $li[(Get-Random -Maximum $MaxNames)]
$Last = $li[(Get-Random -Maximum $MaxNames)]
$Account = "$First.$Last$(Get-Random -Maximum 99)"
[pscustomobject](ConvertFrom-StringData "$($AccountText) = $Account `n $($LastText) = $Last `n $($FirstText) = $First" ) | Select-Object $($FirstText), $($LastText), $($AccountText)
}
}
else {
for ($i = 0; $i -lt $Count; $i++) {
$First = $li[(Get-Random -Maximum $MaxNames)]
$Last = $li[(Get-Random -Maximum $MaxNames)]
[pscustomobject](ConvertFrom-StringData "$($LastText) = $Last `n $($FirstText) = $First" ) | Select-Object $($FirstText), $($LastText)
}
}
}
End {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment