Why not just Google random password generator?  There’s a few out there that 
you can select the complexity that you need.

From: [email protected] [mailto:[email protected]] On 
Behalf Of Keith Garner (HotMail)
Sent: Wednesday, February 03, 2016 2:32 PM
To: [email protected]
Subject: RE: [powershell] Random Password Generator

Here is one I wrote a while back. It will keep trying until the password 
reaches the correct complexity.

function New-UserPassword( [ValidateRange(3,14)] [uint32] $Length = 8 )
{
    # Ensure password meets complexity requirements 
http://technet.microsoft.com/en-us/library/hh994562(v=ws.10).aspx
    [Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null
    do
    {
        $Pass = [System.Web.Security.Membership]::GeneratePassword($Length,2)
        $Complexity = 0
        if ( $Pass -cmatch "\d") {$Complexity++}
        if ( $Pass -cmatch "\W") {$Complexity++}
        if ( $Pass -cmatch "[A-Z]") {$Complexity++}
        if ( $Pass -cmatch "[a-z]") {$Complexity++}
    }
    while ( $Complexity -lt 3 )
    $Pass | Write-Output
}



From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Sean Martin
Sent: Wednesday, February 3, 2016 12:24 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] Random Password Generator

I don't get the opportunity to contribute all that often so I thought I would 
throw this out there in case it helps anyone.

I got the method from this article: 
https://www.scriptjunkie.us/2013/09/secure-random-password-generation/

I modify the resulting password by prepending/appending a couple of special and 
numerical characters to ensure it meets complexity requirements in my current 
environment.

Easy way to generate a secure password whenever the need arises. Critiques are 
always welcome.

===================================================================

# Generate Random Password

$randombytes = new-object byte[] 15
(new-object 
System.Security.Cryptography.RNGCryptoServiceProvider).GetBytes($randombytes)
$pass = [System.Convert]::ToBase64String($randombytes)
$password = "&#" + $pass + "82"

Write-Host ""
Write-Host "Your password is: " -ForeGroundColor Cyan -NoNewLine
Write-Host "$Password" -ForeGroundColor Yellow
Write-Host ""
Write-Host ""
Write-Host "Press enter to exit script..." -ForeGroundColor Cyan

$Pause = Read-Host
Exit

==================================================================

- Sean

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

Reply via email to