Skip to content

Instantly share code, notes, and snippets.

@sirsql
Created May 4, 2022 17:15
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 sirsql/4fdef8ca7e6cd74454583432c1f2fd65 to your computer and use it in GitHub Desktop.
Save sirsql/4fdef8ca7e6cd74454583432c1f2fd65 to your computer and use it in GitHub Desktop.
Creates a new password of specified length
#Creates a new password of specified length using characters within the random character set
function Get-NewPassword ([int32]$PasswordLength) {
if (!$PasswordLength) { $PasswordLength = 42 }
[string]$CharacterSet = 'abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ!@#$%^&*()[]{},.<>/?'
$RandomChar = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $CharacterSet.length }
$ofs = ""
[string]$CharacterSet[$RandomChar]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment