scripts/public/New-Passphrase.ps1
function New-Passphrase { [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'Low', DefaultParameterSetName = 'New')] [OutputType( [string], [psobject])] Param ( [Parameter( ParameterSetName = 'New', Mandatory = $false, Position = 0, HelpMessage = 'Amount of words to get')] [ValidateNotNullOrEmpty()] [int] $AmountOfWords = 3, [Parameter( Mandatory = $false, Position = 3, HelpMessage = 'Separator to use between words')] [ValidateNotNullOrEmpty()] [char] $Separator = " ", [Parameter( Mandatory = $false, HelpMessage = 'Includes numbers')] [switch] $IncludeNumbers, [Parameter( Mandatory = $false, Position = 1, HelpMessage = 'Amount of numbers to include')] [ValidateNotNullOrEmpty()] [int] $AmountOfNumbers = 1, [Parameter( Mandatory = $false, HelpMessage = 'Include an uppercase word')] [switch] $IncludeUppercase, [Parameter( Mandatory = $false, HelpMessage = 'Include special characters')] [switch] $IncludeSpecials, [Parameter( Mandatory = $false, Position = 2, HelpMessage = 'Amount of special characters to include')] [int] $AmountOfSpecials = 1, [Parameter( Mandatory = $false, HelpMessage = 'Return passphrase as object')] [switch] $AsObject, [Parameter( ParameterSetName = 'Custom', Mandatory = $true, ValueFromPipeline = $true, HelpMessage = 'Custom string to build passphrase object from')] [string] $CustomString ) $ErrorActionPreference = 'Stop' $InformationPreference = 'Continue' if (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } if (-not $PSBoundParameters.ContainsKey('Confirm')) { $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference') } if (-not $PSBoundParameters.ContainsKey('WhatIf')) { $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference') } Write-Verbose ('[{0}] Confirm={1} ConfirmPreference={2} WhatIf={3} WhatIfPreference={4}' -f $MyInvocation.MyCommand, $Confirm, $ConfirmPreference, $WhatIf, $WhatIfPreference) if ($PSCmdlet.ShouldProcess("Generates a new random passphrase")) { try { if ($PSBoundParameters.ContainsKey('CustomString')) { $Passphrase = [Passphrase]::new($CustomString, $Separator) } else { [array]$Words = . (Join-Path (Split-Path $PSScriptroot) 'private\Passphraser.Words.ps1') $Passphrase = [Passphrase]::new($Words, $AmountOfWords, $Separator) } if ($PSBoundParameters.ContainsKey('IncludeUppercase')) { $Passphrase.AddUppercase() } if ($PSBoundParameters.ContainsKey('IncludeNumbers')) { $Passphrase.AddNumber($AmountOfNumbers) } if ($PSBoundParameters.ContainsKey('IncludeSpecials')) { $Passphrase.AddSpecial($AmountOfSpecials) } if ($PSBoundParameters.ContainsKey('AsObject')) { return $Passphrase } else { return $Passphrase.ToString() } } catch { $PSCmdlet.throwTerminatingError($PSItem) } } } # SIG # Begin signature block # MIIM+AYJKoZIhvcNAQcCoIIM6TCCDOUCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUwixeC6OFqYkeC2aE/1X77RFr # lF+gggo/MIIFGTCCBAGgAwIBAgIQDbnGEbOq/3RgewIGXryqxTANBgkqhkiG9w0B # AQsFADBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD # VQQLExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVk # IElEIFJvb3QgQ0EwHhcNMTQxMTE4MTIwMDAwWhcNMjQxMTE4MTIwMDAwWjBtMQsw # CQYDVQQGEwJOTDEWMBQGA1UECBMNTm9vcmQtSG9sbGFuZDESMBAGA1UEBxMJQW1z # dGVyZGFtMQ8wDQYDVQQKEwZURVJFTkExITAfBgNVBAMTGFRFUkVOQSBDb2RlIFNp # Z25pbmcgQ0EgMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKri5yAv # rBCV+s0k5fig3/WirZ+8s8n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