Skip to content

Instantly share code, notes, and snippets.

@steve-codemunkies
Created September 23, 2015 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve-codemunkies/36b21b65170b9678a625 to your computer and use it in GitHub Desktop.
Save steve-codemunkies/36b21b65170b9678a625 to your computer and use it in GitHub Desktop.
Function New-Password {
param([int]$length = 12,
[int]$complexity = 4)
[String[]]$source = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "1234567890", "[]{}<>@#~?!£$%^&*()"
$newPassword = $null
foreach($counter in 1..$length) {
# Work out which character type to get
$set = Get-Random $complexity
$position = Get-Random $source[$set].length
# Add a character from the specified set to the new password
$newPassword = $newPassword + [char]($source[$set].SubString($position, 1))
}
return $newPassword
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment