Here is another small script to produce random passwords consisting of a defined number of capitals, letters, numbers, and special characters:

$length = 10
$length_small = $length - 3
$numbers = '2,3,4,5,6,7,8,9' -split ','
$large = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z' -split ','
$small = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z'.ToLower() -split ','
$special = '!,§,$,='.Split(',')

$password = @()
$password = @($numbers | Get-Random)
$password += @($large | Get-Random)
$password += @($small | Get-Random -Count $length_small)
$password += @($special | Get-Random)

$password = $password | Get-Random -Count $length

$password -join ''

Are you an experienced professional PowerShell user? Then learning from default course work isn’t your thing. Consider learning the tricks of the trade from one another! Meet the most creative and sophisticated fellow PowerShellers, along with Microsoft PowerShell team members and PowerShell inventor Jeffrey Snover. Attend this year’s PowerShell Conference EU, taking place April 17-20 in Hanover, Germany, for the leading edge. 35 international top speakers, 80 sessions, and security workshops are waiting for you, including two exciting evening events. The conference is limited to 300 delegates. More details at www.psconf.eu.

Twitter This Tip! ReTweet this Tip!

Anonymous
  • How about native functionality?


    $PasswordLength = 15
    $NumberOfNonAlphanumericCharacters = 3

    [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
    Return [System.Web.Security.Membership]::GeneratePassword($PasswordLength,$NumberOfNonAlphanumericCharacters)

  • How about native functionality?


    $PasswordLength = 15
    $NumberOfNonAlphanumericCharacters = 3

    [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
    Return [System.Web.Security.Membership]::GeneratePassword($PasswordLength,$NumberOfNonAlphanumericCharacters)