Execution Flow
Uses
System.Security.Cryptography.RandomNumberGenerator instead of Get-Random for cryptographic strength. Ambiguous characters (I O i l o 0 1) are excluded from all pools. Only a SecureString is returned — the plaintext copy is cleared from memory immediately after use.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -Length | Int | Optional | Password length, 12–128. Default: 20. |
| -ExportPath | String | Optional | If given, exports a DPAPI-encrypted (current user/machine) copy via ConvertFrom-SecureString. |
Return Value
Returns a System.Security.SecureString containing the generated password. No plaintext is returned.
Examples
Example 1 — Generate a default 20-character password
$saPwd = New-sqmRandomSaPassword
Example 2 — Generate and export an encrypted backup copy
$saPwd = New-sqmRandomSaPassword -Length 32 -ExportPath "C:\Secure\sa-pwd.xml"