Builds a password from a cryptographic random number generator, guarantees one character from each class, and shuffles the result with Fisher-Yates rather than sorting on a random key. Ambiguous characters are left out of the alphabets, so nobody has to guess whether that is a one or an l when they read it back over the phone. Hands the password to the next runbook step.
powershell
# Generate a Random Password
# Single use case: create a strong password and hand it to the next
# runbook script via $store (ex. chain with 00-AD-USER-ResetPassword.ps1)
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
# --- Parameters (replace via ServerEngine API parameters if needed) ---
$Length = 16
$lower = "abcdefghijkmnopqrstuvwxyz" # no l
$upper = "ABCDEFGHJKLMNPQRSTUVWXYZ" # no I/O
$digits = "23456789" # no 0/1
$symbols = "!#%+-=?@"
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
function Get-RandomChar([string]$set) {
$bytes = New-Object byte[] 4
$rng.GetBytes($bytes)
$set[([BitConverter]::ToUInt32($bytes, 0) % $set.Length)]
}
# guarantee one of each class, fill the rest from the full set
$all = $lower + $upper + $digits + $symbols
$chars = @((Get-RandomChar $lower), (Get-RandomChar $upper), (Get-RandomChar $digits), (Get-RandomChar $symbols))
while ($chars.Count -lt [int]$Length) { $chars += Get-RandomChar $all }
# shuffle (Fisher-Yates with crypto RNG)
for ($i = $chars.Count - 1; $i -gt 0; $i--) {
$bytes = New-Object byte[] 4
$rng.GetBytes($bytes)
$j = [BitConverter]::ToUInt32($bytes, 0) % ($i + 1)
$tmp = $chars[$i]; $chars[$i] = $chars[$j]; $chars[$j] = $tmp
}
$password = -join $chars
$rng.Dispose()
Write-Log "Generated a $Length character password (stored in `$store for the next script)."
# Deliberately NOT logged in clear text - it travels via $store only.
$store = $passwordRun it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in System Administration
Get the Public IP Address with PowerShell
2026-08-17Send a Wake-on-LAN Magic Packet with PowerShell
2026-08-17Force a Windows Shutdown with PowerShell
2026-08-17Download and Extract Files with BITS in PowerShell
2026-08-17Check Linux Uptime and Disk Usage over SSH
2026-08-17Automated System Information Gatherer Script
2025-01-14Ready when you are.
Try ServerEngine free for 7 days.