53 lines
1.3 KiB
PowerShell
53 lines
1.3 KiB
PowerShell
function Get-PyNString {
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(
|
|
Position = 0
|
|
)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[ValidateScript({
|
|
if ($_ -lt 6) {
|
|
throw $"$_ has invalid length. It must be 6 or greater."
|
|
} else { $true }
|
|
})]
|
|
#Length of the string to generate. Must be at least 6.
|
|
[int]$Length = 6
|
|
)
|
|
|
|
Write-Host $(python -c "import string,random; print(''.join(random.SystemRandom().choice(string.digits+string.ascii_letters) for _ in range ($Length)))")
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Generate N-chars long string using python
|
|
.DESCRIPTION
|
|
Generate N-chars long string using python. Can be used to generate random passwords.
|
|
.EXAMPLE
|
|
PS> Get-Py32String
|
|
Y09Sk6TLNKAEqgEVaUPHsMZ6zA4I0Zzs
|
|
.EXAMPLE
|
|
PS> Get-Py16String
|
|
Mca6nUotYpWLdoyD
|
|
.EXAMPLE
|
|
PS> Get-Py8String
|
|
15g0DJKP
|
|
.LINK
|
|
https://git.potyra.net/dawidp/powershell/wiki/PyNStrings
|
|
#>
|
|
}
|
|
|
|
function Get-Py32String {
|
|
Write-Host $(Get-PyNString 32)
|
|
}
|
|
|
|
function Get-Py16String {
|
|
Write-Host $(Get-PyNString 16)
|
|
}
|
|
|
|
function Get-Py8String {
|
|
Write-Host $(Get-PyNString 8)
|
|
}
|
|
|
|
New-Alias py32s Get-Py32String
|
|
New-Alias py16s Get-Py16String
|
|
New-Alias py8s Get-Py8String
|