Functions/Get-RandomPassword.ps1

<#
.SYNOPSIS
Generates complex or simple random passwords
 
.DESCRIPTION
Uses Get-Random to generate passwords of arbitrary length from a set of characters.
If you set the simple-flag it will use a simplified character-pool to generate passwords which can be spelled more easily.
 
.PARAMETER Length
Length of password to generate
 
.PARAMETER Simple
If specified generates a simple password
 
.EXAMPLE
New-Password -Length 16
 
Description
-----------
Generate a 16 character password with complex characters
 
.EXAMPLE
New-Password -Length 12 -Simple
 
Description
-----------
Generate a 12 character password with simplified characters
#>

function Get-RandomPassword {
    [CmdletBinding()]
    [OutputType([String])]
    Param
    (
        [Int]$Length = 14,

        [Switch][Bool]$Simple
    )

    Begin {
        $SimpleChars = ('!ABCDEFGHKLMNPRSTUVWXYZ!abcdefghkmnprstuvwxyz!123456789!').ToCharArray()
        $ComplexChars = (33..122 | ForEach-Object {([char]$_).ToString()}).ToCharArray()
    }

    Process {
        if ($Simple) {
            $Chars = $SimpleChars
        }
        else {
            $Chars = $ComplexChars
        }

        Write-Output -InputObject ((Get-Random -Count $Length -InputObject $Chars) -join '')
    }

    End {
    }
}