

Here is the full script: Function GeneratePassword Get-Random -Count $PasswordLength) -replace ' ') $Password = (($AllowedPasswordCharacters | The answer to your question about always including a number in your generated output can be solved by checking the output with a regex match (just use the parts of the regex that you need, based on the explanations above), the example here checks for uppercase, lowercase, and numerical: $Regex = "(?=.*\d)(?=.*)(?=.*)" (?=.*\W) must contain at least one non-word character (?=.*) must contain at least one uppercase character (?=.*) must contain at least one lowercase character (?=.*\d) must contain at least one numerical character It also allows an easy to edit character set, and also has a regex to ensure a decent password has been generated with all of the following characteristics: (To hard set a password length, just set the MinimumPasswordLength and MaximumPasswordLength values to the the same length.) The difference in this script is that the password length can also be randomised. Similar to the accepted answer, this script also uses Get-Random (twice), and also regular expression matching to ensure the output is secure.
#Need alphanumeric password generator generator#
I wrote a secure password generator function in PowerShell, maybe this will be useful to someone. $pass = (($pass.GetEnumerator() | Get-Random -Count $pass.Length) -join '') $pass += ($set.GetEnumerator() | Get-Random) This is my previous password for my previous password account manager. To think it is feasible to store and use such table is just preposterous. \Get-RandomPassword.ps1 -Characters ($sets -join '') An alphanumeric password (lowercase, uppercase and numbers) of just 10 characters has 839.299.366.000.000.000 possible combinations. That's why I reinvented the wheel: Function Create-String($Size = 8, ]$CharSets = "ULNS", ]$Exclude) :''",/?`~')

As suggested by jisaak, there is no 100% guaranty that the Membership.GeneratePassword Method generates a password that meets the AD complexity requirements.
