Generate strong passwords using PowerShell

Few days ago I need to generate set of passwords for Azure SQL Database. Password policy for Azure Active Directory and MSSQL specifies requirements for password generator. PowerShell script for strong password generation:

$specialChars = @("!", "$", "#", "%")

$guid = [System.Guid]::NewGuid().ToString("n")
$sb = New-Object System.Text.StringBuilder

for ($i = 0; $i -lt $guid.Length; $i++)
    $c = $guid[$i]

    if (($i % 2 -eq 0) -and [System.Char]::IsLetter($c))
        $c = [System.Char]::ToUpper($c)

    $random = Get-Random -Minimum 1 -Maximum 100

    if ($random % 7 -eq 0)
        $c = Get-Random $specialChars

    $sb.Append($c) | Out-Null


Udemy course: Improve your productivity with PowerShell

Password generator is based on the System.Guid.NewGuid() method which generates 32 character length password base containing lowercase letters and numbers. In the next step are some letters transformed to uppercase or replaced by special characters. Passwords generated by script are like this:


If you are interested in PowerShell automation, take my Udemy course Improve your productivity with PowerShell.