Generate random password: Difference between revisions

From roonics
Jump to navigation Jump to search
(Created page with "<pre> # Usage: random-password <length> Function random-password ($length = 15) { $punc = 40..60 $digits = 48..57 $letters = 65..90 + 97..122 $...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Generate a random password using powershell.
<pre>
<pre>
# Usage: random-password <length>
# Usage: random-password <length>
Line 23: Line 25:
Write-Host -ForegroundColor "Green" "$text"
Write-Host -ForegroundColor "Green" "$text"
</pre>
</pre>
Example output:
<pre style="color: white; background: #012456; width: 800px">
PS C:\Users\lab>.\generate-random-password.ps1
jB8v5.FCG:K2*QWU
</pre>
[[Category:PowerShell]]
[[Category:scripts]]
‎<comments />

Latest revision as of 10:04, 20 March 2022

Generate a random password using powershell.

# Usage: random-password <length>
Function random-password ($length = 15)
{
        $punc = 40..60
        $digits = 48..57
        $letters = 65..90 + 97..122
        $password = get-random -count $length `
                -input ($punc + $digits + $letters) |
                        % -begin { $aa = $null } `
                        -process {$aa += [char]$_} `
                        -end {$aa}
        return $password
}

Write-Host "Generating random password and copying to clipboard"
random-password 16 | clip
$text = & {powershell –sta {add-type –a system.windows.forms; [windows.forms.clipboard]::GetText()}}
sleep -m 100
Write-Host "..."
sleep -m 100
Write-Host "..."
Write-Host -ForegroundColor "Green" "$text"

Example output:

PS C:\Users\lab>.\generate-random-password.ps1
jB8v5.FCG:K2*QWU

‎<comments />