Author Posts

May 28, 2016 at 6:14 am

May 28, 2016 at 6:19 am

I am trying to create a password generator in powershell

The problem is when I run the function the results are not always predictable

For example:
get-randompassword -UppercaseAlphachracters 1 -LowercaseAlphaChracters 1 -SpecialChracters 1 -NumericChracters 5

most of the time it gives me the amount I have requested:
5 numeric chracters
etc etc...

other times it is one less that the specified values.

what am I missing here?

May 28, 2016 at 10:57 am

While its awesome that you're playing around and making your own scripts, you can generate random passwords in PowerShell with a single line.

Add-Type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword(12,5)

In this line of code, the '5' indicates the Number of non alphanumeric characters while the '12' indicates the password Length.

  • This reply was modified 2 years, 2 months ago by  Flynn Bundy.

May 28, 2016 at 10:41 pm

Have a look t this:

-join ((65..90) + (97..122) | Get-Random -Count 12 | % {[char]$_})

It could make this mutch easier.

  • This reply was modified 2 years, 2 months ago by  Chris Bakker.