Added list-random-pins1.ps1

This commit is contained in:
Markus Fleschutz 2020-12-22 09:12:50 +00:00
parent c40d0fa110
commit 093dc5c92a
3 changed files with 51 additions and 12 deletions

View File

@ -20,6 +20,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [list-earthquakes.ps1](Scripts/list-earthquakes.ps1) - lists earthquakes >= 6.0 for the last 30 days
* [list-modules.ps1](Scripts/list-modules.ps1) - lists the PowerShell modules
* [list-random-passwords.ps1](Scripts/list-random-passwords.ps1) - prints a list of random passwords
* [list-random-pins.ps1](Scripts/list-random-pins.ps1) - prints a list of random PIN's
* [list-processes.ps1](Scripts/list-processes.ps1) - lists the local computer processes
* [locate-city.ps1](Scripts/locate-city.ps1) - prints the geographic location of the given city
* [locate-ipaddress.ps1](Scripts/locate-ipaddress.ps1) - prints the geographic location of the given IP address

View File

@ -6,31 +6,33 @@
# Source: github.com/fleschutz/PowerShell
# License: CC0
$CharsPerPassword = 15
$PasswordLength = 15
$Columns = 6
$Lines = 24
$MinCharCode = 33
$MaxCharCode = 126
$Lines = 24
$Columns = 6
function GeneratePassword() {
$password = ""
$generator = New-Object System.Random
for ($i = 0; $i -lt $CharsPerPassword; $i++) {
$password = $password +[char]$generator.next($MinCharCode,$MaxCharCode)
$Generator = New-Object System.Random
for ($i = 0; $i -lt $PasswordLength; $i++) {
$Result += [char]$Generator.next($MinCharCode,$MaxCharCode)
}
return $password
return $Result
}
try {
write-output ""
for ($j = 0; $j -lt $Lines; $j++) {
$Line = ""
for ($k = 0; $k -lt $Columns; $k++) {
$password = GeneratePassword
Write-Host -NoNewline "$password "
$Line += GeneratePassword
$Line += " "
}
Write-Host ""
write-output $Line
}
write-output ""
exit 0
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

36
Scripts/list-random-pins.ps1 Executable file
View File

@ -0,0 +1,36 @@
#!/snap/bin/powershell
# Syntax: ./list-random-pins.ps1
# Description: prints a list of random PIN's
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
$PIN_Length = 5
$Columns = 12
$Lines = 24
function GeneratePIN() {
$Generator = New-Object System.Random
for ($i = 0; $i -lt $PIN_Length; $i++) {
$PIN += [char]$Generator.next(48,57)
}
return $PIN
}
try {
write-output ""
for ($j = 0; $j -lt $Lines; $j++) {
$Line = ""
for ($k = 0; $k -lt $Columns; $k++) {
$Line += GeneratePIN
$Line += " "
}
write-output $Line
}
write-output ""
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}