Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created September 19, 2016 03:45
Show Gist options
  • Save chrisbrownie/8ab939d080225930f85184df00c95d3b to your computer and use it in GitHub Desktop.
Save chrisbrownie/8ab939d080225930f85184df00c95d3b to your computer and use it in GitHub Desktop.
Generates a random phone number (completely random, not necessarily a valid one)
function Get-RandomNumber ([int]$min,[int]$max,[switch]$leadingZeroes) {
$number = Get-Random -Minimum $min -Maximum $max
if ($leadingZeroes) {
if ($number.ToString().Length -lt $max.ToString().Length) {
$number.Tostring().PadLeft($max.ToString().Length,"0")
} else {
$number.ToString()
}
} else {
$number.ToString()
}
}
$("+" + `
$(Get-RandomNumber -min 1 -max 99 -leadingZeroes) + `
" " + `
$(Get-RandomNumber -min 0 -max 9 -leadingZeroes) + `
" " + `
$(Get-RandomNumber -min 0 -max 9999 -leadingZeroes) + `
" " + `
$(Get-RandomNumber -min 0 -max 9999 -leadingZeroes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment