Created
May 4, 2022 17:15
-
-
Save sirsql/4fdef8ca7e6cd74454583432c1f2fd65 to your computer and use it in GitHub Desktop.
Creates a new password of specified length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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