New-Password.ps1

Function New-Password
{
    <#
    .SYNOPSIS
        Passwords generator
 
    .DESCRIPTION
        The New-Password cmdlet allow to generate pools of random passwords.
         
    .PARAMETER Pool
        Specifies pool length. Default is 10 random password.
 
    .PARAMETER CharsLengthArray
        Specifies array of chars used in password.
        Default is (2,6,2,0):
        2 digits,
        6 small letters,
        2 big letters,
        0 special chars
     
    .EXAMPLE
        PS H:\> New-Password
        C3fh5imoxJ
        7kcvri4NYp
        tqPHcr28id
        jsGdcl4eD7
        deczf0jL7Y
        Rcv2zh4Jka
        E8uaLhbci5
        r38mGeTlgk
        gSRfqzy72r
        t7QehOpkj2
 
    .NOTES
        Author: Michal Gajda
    #>

    
    [CmdletBinding()] 
    Param
    (
        [Int]$Pool = 10,
        [Int[]]$CharsLengthArray = (2,6,2,0)
    )
    
    1..$Pool | ForEach-Object {
        $CharsD = 48..57  | ForEach-Object {[Char]$_}  #[Char[]]"1234567890"
        $CharsL = 97..122 | ForEach-Object {[Char]$_}  #[Char[]]"abcdefghijklmnopqrstuvxyz"
        $CharsU = 65..90  | ForEach-Object {[Char]$_}  #[Char[]]"ABCDEFGHIJKLMNOPQRSTUVXYZ"
        $CharsS = [Char[]]"()`~!@#$%^&*-+=|\{}[]:;',.?/"
        
        $Password = ""
        
        if($CharsLengthArray[0] -gt 0) { $Password += ($CharsD | Get-Random -Count $CharsLengthArray[0]) -join "" }
        if($CharsLengthArray[1] -gt 0) { $Password += ($CharsL | Get-Random -Count $CharsLengthArray[1]) -join "" }
        if($CharsLengthArray[2] -gt 0) { $Password += ($CharsU | Get-Random -Count $CharsLengthArray[2]) -join "" }
        if($CharsLengthArray[3] -gt 0) { $Password += ($CharsS | Get-Random -Count $CharsLengthArray[3]) -join "" }
        $Password = ($Password.ToCharArray()| Sort-Object {Get-Random}) -join ""
        
        $Password
    }
}