Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (42 sloc) 1.52 KB
<#
.SYNOPSIS
Get a "random" password of a given length with PowerShell and copy to clipboard. Easy copy-paste for service account setup etc.
License: BSD 3-Clause
.DESCRIPTION
Get a "random" password of a given length with PowerShell and copy to clipboard. Easy copy-paste for service account setup etc.
Recommended use for service accounts etc.:
A) Get-RandomPassword -min 40 -max 127
B) Get-RandomPassword -min 40
.LINK
Get latest version here: https://github.com/improsec/Get-RandomPassword
.NOTES
Authored by : Improsec ApS / @Improsec
Date created : 14/06-2016
Last modified : 04/03-2019
Find us here:
- https://www.improsec.com
- https://github.com/improsec
- https://twitter.com/improsec
- https://www.facebook.com/improsec
Tested on:
- Windows 7, 8 and 10 + server versions
#>
Param
(
[parameter(Mandatory=$false)]
[alias("min")]
[ValidateRange(8,127)]
[int]$MinimumPasswordLength = 8,
[parameter(Mandatory=$false)]
[alias("max")]
[ValidateRange(8,127)]
[int]$MaximumPasswordLength = 127
)
# Make random password string
If ($MinimumPasswordLength -eq 127) {$RndLength = $MinimumPasswordLength}
Else {$RndLength = Get-Random -minimum $MinimumPasswordLength -maximum ($MaximumPasswordLength + 1)}
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
$strRandomPassword = [System.Web.Security.Membership]::GeneratePassword($RndLength,2)
# Output
$strRandomPassword | Set-Clipboard
$strRandomPassword
You can’t perform that action at this time.