GetPassPhrase.psm1
|
Function Get-Passphrase { param( [Parameter(Mandatory = $false, Position = 0)] [int]$Count = 1, [Parameter(Mandatory = $false, Position = 1)] [switch]$Refresh = $False ) #$ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition If ($Refresh -eq $True -or !($words = Get-Content -Path $PSScriptRoot\words.txt -ErrorAction SilentlyContinue)) { [array]$words = (((Invoke-WebRequest -Uri https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt).content).split(" ")) -replace "[^a-zA-Z]" $words | Out-File $PSScriptRoot\words.txt } $loop = 0 do { # This IsNotNullOrEmpty nonsense is required for Windows PowerShell 5.1 and PowerShell Core -lt 7.0. Get-Random gives an error if it thinks there's a null or empty in the InputObject $Pass = If (-not [string]::IsNullOrEmpty($Words)) { $words | Get-Random -count 3 -ErrorAction SilentlyContinue } $num = Get-Random -Maximum 10 $NewPassword = $pass[0] + "-" + ($pass[1]).ToUpper() + "-" + $pass[2] + $num $NewPassword $loop++ } while ($loop -lt $count) } |