As Admins, when you create new accounts or need to reset account passwords, the first thing that comes to mind is just use “Pass@123” or “Password” because it is easy, however if you forget to force users to change passwords, they will use this all the time which is a security risk.

I wanted something to use that is convenient and easy and you don’t need to use a tool on the internet that is generally blocked by firewalls.

I put together a PowerShell Script that creates, 12, 16 and 32 character passwords, with lower case, uppercase and special characters included. Here is the output of this:

Quickly generate random passwords for accounts in exchange 2019 with powershell

SCRIPT

There is not need to modify the script unless you want to change the length of the passwords which you can do on line 3, line 19 and line 23. Here is the script for you to use:

function Generate-RandomPassword {
    param(
        [int]$length = 12
    )

    $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+'
    $random = New-Object -TypeName System.Random
    $shuffledCharacters = $characters.ToCharArray() | Get-Random -Count $characters.Length
    $password = -join ($shuffledCharacters[0..($length-1)])

    return $password
}

# Usage example with default length (12 characters)
$randomPassword = Generate-RandomPassword
Write-Output "Random Password (12 characters): $randomPassword"

# Usage example with custom length (e.g., 16 characters)
$customLengthPassword = Generate-RandomPassword -length 16
Write-Output "Random Password (16 characters): $customLengthPassword"

# Usage example with custom length (e.g., 32 characters)
$customLengthPassword = Generate-RandomPassword -length 32
Write-Output "Random Password (32 characters): $customLengthPassword"

I used PowerShell ISE and the Exchange Management Shell to run this and it worked without an issue.

Hope you find it helpful.

Discover more from Everything-PowerShell

Subscribe now to keep reading and get access to the full archive.

Continue reading