PoshCode Logo PowerShell Code Repository

Password Gen v.20170412 by AlphaSun 2 weeks ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6841"></script>download | new post

Functions: New-PIN, New-Password, New-PassPhrase

Provides quick access to randomly generated PINs, Passwords, and Pass Phrases.

New-PIN: Provides PINs of various lengths from 1-19 digits as Integers and PINs of 20 or more digits as Strings.

New-Password: Provides a random password with the given parameters. The default length is 12 characters. If you wish to omit a particular character set (eg. Symbols), you need to specify the total password length as well as how many characters from each set should be included. The sum of all selected sets should equal the total number of characters desired in the password. If the sum of the selected sets is less than the total, it is possible that a character from the undesired set may be included in the generated password.

New-PassPhrase: Provides a random pass phrase using words from a word list loaded into the $PasswdList variable. The overall security of the provided passwords depends greatly on the size of the word list you use—the more words, the bigger the haystack. With no defined switches, the function will randomly select 4 words from the word list, generate 4 random digits, and use the “-” as a separator character. Words are randomly capitalized. The number of words, number of digits, letter case, separator character, padding character, and total pass phrase length are configurable in addition to your choice of word list to use. A word list of 5,000-20,000 words is recommended to provide a large enough haystack while maintaining speed. Larger word lists can be used, but speed begins to noticeably decrease with word lists larger than 20,000 words. For most applications, word lists of 5,000-10,000 words will provide a sufficiently sized haystack with nominal recurrence of grouped words.

Check-Even: Simple function to check if a number is even. Used in the New-PassPhrase function to randomize capitalization of words.

  1. Function Compare-Even($num){ # Dependency for New-PassPhrase function
  2.         [bool]!($num%2)
  3. }
  4.  
  5. Function New-PIN{
  6. #       .SYNOPSIS
  7. #               Generate PIN numbers randomly.
  8. #
  9. #       .DESCRIPTION
  10. #               This function can be used to generate PIN numbers of varying lengths.
  11. #
  12. #       .PARAMETER -Digits [<int>]
  13. #                       Specifies the number of words the passphrase should contain. Minimum value is 1.
  14. #                      
  15. #                       Required?                                       false
  16. #                       Position?                                       0
  17. #                       Default value                           4
  18. #                       Accept pipeline input?          true
  19. #                       Accept wildcard characters?     false
  20. #                      
  21. #       .PARAMETER -Generate [<int>]
  22. #                       Specifies the number of passphrases to generate. All passphrases generated will comply with the parameters set.
  23. #                      
  24. #                       Required?                                       false
  25. #                       Position?                                       null
  26. #                       Default value                           1
  27. #                       Accept pipeline input?          true
  28. #                       Accept wildcard characters?     false
  29. #              
  30. #       .EXAMPLE
  31. #               New-PIN
  32. #      
  33. #               Description
  34. #               -----------
  35. #               Generates a random PIN that is 4-digits long.
  36. #
  37. #       .EXAMPLE
  38. #               New-PIN -Digits 6 -Generate 10
  39. #
  40. #               Description
  41. #               -----------
  42. #               Generates 10 PINs that are each 6-digits long.
  43. #
  44. #       .EXAMPLE
  45. #               New-PIN -Generate 20
  46. #
  47. #               Description
  48. #               -----------
  49. #               Generates 20 PINs that are each 4-digits long.
  50. #
  51. #
  52. #
  53.         [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
  54.         param(
  55.                 [parameter(Mandatory = $false, Position = 0)]
  56.                 [ValidateRange(1,([int]::MaxValue))][int]$Digits = 4,
  57.                 [parameter(Mandatory = $false, Position = 1)]
  58.                 [ValidateRange(1,([int]::MaxValue))][int]$Generate = 1
  59.         )
  60.         For($i=0;$i -lt $Generate;$i++){
  61.                 $NC = 0
  62.                 [string]$PIN = ""
  63.                 While($NC -lt $Digits){
  64.                         $PIN += Get-Random -Minimum 0 -Maximum 10
  65.                         $NC += 1
  66.                 }
  67.                 Write-Host $PIN.Length "digits:  " -NoNewLine
  68.                 Write-Host $PIN
  69.                 Remove-Variable PIN
  70.         }
  71. }
  72.  
  73. Function New-Password{
  74. #       .SYNOPSIS
  75. #               Generate passphrases randomly.
  76. #
  77. #       .DESCRIPTION
  78. #               This function can be used to generate passwords of varying lengths and complexities.
  79. #
  80. #               The user can specify the desired total password length as well as the character set to use. By default, the
  81. #               'All' character set is used and includes upper case letters, lower case letters, numbers, and all
  82. #               keyboard-printable symbols. A custom number of passwords to generate can also be specified.
  83. #
  84. #       .PARAMETER -Total [<int>]
  85. #                       Specifies the number of words the passphrase should contain. Minimum value is 1.
  86. #                      
  87. #                       Required?                                       false
  88. #                       Position?                                       0
  89. #                       Default value                           16
  90. #                       Accept pipeline input?          true
  91. #                       Accept wildcard characters?     false
  92. #                      
  93. #       .PARAMETER -CharacterSet [<string>]
  94. #                       Specifies the character set to use. Valid selections are: All, AlphaNumericMixed, AlphaNumericUpper,
  95. #                       AlphaNumericLower, AlphaSymbolMixed, AlphaSymbolUpper, AlphaSymbolLower, AlphaMixed, AlphaLower, AlphaUpper,
  96. #                       SymbolNumeric, and SymbolOnly. If not specified, the default is used.
  97. #                      
  98. #                       Required?                                       false
  99. #                       Position?                                       null
  100. #                       Default value                           All
  101. #                       Accept pipeline input?          true
  102. #                       Accept wildcard characters?     false
  103. #                      
  104. #       .PARAMETER -Generate [<int>]
  105. #                       Specifies the number of passphrases to generate. All passphrases generated will comply with the parameters set.
  106. #                      
  107. #                       Required?                                       false
  108. #                       Position?                                       null
  109. #                       Default value                           1
  110. #                       Accept pipeline input?          true
  111. #                       Accept wildcard characters?     false
  112. #              
  113. #       .EXAMPLE
  114. #               New-Password
  115. #      
  116. #               Description
  117. #               -----------
  118. #               Generates a random password using the default parameters
  119. #
  120. #       .EXAMPLE
  121. #               New-Password -Total 8 -CharacterSet AlphaNumericUpper -Generate 6
  122. #
  123. #               Description
  124. #               -----------
  125. #               Generates 6 passwords that are each 8-characters long using only uppercase letters and numbers.
  126. #
  127. #       .EXAMPLE
  128. #               New-Password -Generate 20
  129. #
  130. #               Description
  131. #               -----------
  132. #               Generates 20 passwords that are each 16-characters long using characters from all character sets.
  133. #
  134. #
  135. #
  136.  
  137.         [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
  138.         param(
  139.                 [parameter(Mandatory = $false, Position = 0)]
  140.                 [ValidateRange(1,([int]::MaxValue))][int]$Total = 16,
  141.                 [ValidateSet("All","AlphaNumericMixed","AlphaNumericUpper","AlphaNumericLower","AlphaSymbolMixed","AlphaSymbolUpper","AlphaSymbolLower","AlphaMixed","AlphaLower","AlphaUpper","SymbolNumeric","SymbolOnly")][string]$CharacterSet = "All",
  142.                 [parameter(Mandatory = $false, Position = 1)]
  143.                 [ValidateRange(1,([int]::MaxValue))][int]$Generate = 1
  144.         )
  145.         Process{
  146.                 For($i=0;$i -lt $Generate;$i++){
  147.                         [string]$Passwd = ''
  148.                         $UC = $NULL;For($a=65;$a -le 90;$a++){$UC+=,[char][byte]$a}
  149.                         $LC = $NULL;For($a=97;$a -le 122;$a++){$LC+=,[char][byte]$a}
  150.                         $NU = $NULL;For($a=48;$a -le 57;$a++){$NU+=,[char][byte]$a}
  151.                         $SY = ("!","@","#","$","%","^","&","*","(",")","{","}","[","]","\","|","/","?","<",">",",",".","-","+","_","=",";",":")
  152.                         If($CharacterSet -eq "All"){
  153.                                 $BaseSet = $UC + $LC + $NU + $SY}
  154.                         elseIf($CharacterSet -eq "AlphaNumericMixed"){
  155.                                 $BaseSet = $UC + $LC + $NU}
  156.                         elseIf($CharacterSet -eq "AlphaNumericUpper"){
  157.                                 $BaseSet = $UC + $NU}
  158.                         elseIf($CharacterSet -eq "AlphaNumericLower"){
  159.                                 $BaseSet = $LC + $NU}
  160.                         elseIf($CharacterSet -eq "AlphaSymbolMixed"){
  161.                                 $BaseSet = $UC + $LC + $SY}
  162.                         elseIf($CharacterSet -eq "AlphaSymbolUpper"){
  163.                                 $BaseSet = $UC + $SY}
  164.                         elseIf($CharacterSet -eq "AlphaSymbolLower"){
  165.                                 $BaseSet = $LC + $SY}
  166.                         elseIf($CharacterSet -eq "AlphaMixed"){
  167.                                 $BaseSet = $LC + $UC}
  168.                         elseIf($CharacterSet -eq "AlphaLower"){
  169.                                 $BaseSet = $LC}
  170.                         elseIf($CharacterSet -eq "AlphaUpper"){
  171.                                 $BaseSet = $UC}
  172.                         elseIf($CharacterSet -eq "SymbolNumeric"){
  173.                                 $BaseSet = $SY + $NU}
  174.                         elseIf($CharacterSet -eq "SymbolOnly"){
  175.                                 $BaseSet = $SY}
  176.                         For ($Loop=1;$Loop -le $Total;$Loop++) {
  177.                                 $Passwd += Get-Random -Input $($BaseSet)
  178.                         }
  179.                         Write-Host $Passwd.Length "char:  " -NoNewLine
  180.                         Write-Host $Passwd
  181.                         Remove-Variable Passwd
  182.                 }
  183.         }
  184. }
  185.  
  186. Function New-PassPhrase{
  187. #       .SYNOPSIS
  188. #               Generate passphrases randomly.
  189. #
  190. #       .DESCRIPTION
  191. #               This function can be used to generate passphrases of varying lengths and complexities. The function was created
  192. #               based on the passphrase generator at http://xkpasswd.net/s and attempts to emulate all of its functionality.
  193. #      
  194. #               The function is set with default parameters but is highly configurable. The function utilizes a user-provided
  195. #               word file in CSV format with the header 'Word'. Any word list can be used.
  196. #
  197. #       .PARAMETER -Words [<int>]
  198. #                       Specifies the number of words the passphrase should contain. Minimum value is 1.
  199. #                      
  200. #                       Required?                                       false
  201. #                       Position?                                       0
  202. #                       Default value                           4
  203. #                       Accept pipeline input?          true
  204. #                       Accept wildcard characters?     false
  205. #                      
  206. #       .PARAMETER -WordLength [<int>]
  207. #                       Specifies the length of the words used in the passphrase. If not set, random word lengths are used for each word
  208. #                       in the passphrase. Minimum and maximum word length is dependent upon the word list used. Recommendation is that
  209. #                       the word list used does not contain words with fewer than 4 letters.
  210. #                      
  211. #                       Required?                                       false
  212. #                       Position?                                       1
  213. #                       Default value                           null
  214. #                       Accept pipeline input?          true
  215. #                       Accept wildcard characters?     false
  216. #                      
  217. #       .PARAMETER -NumbersBefore [<int>]
  218. #                       Specifies the number of random digits to place at the beginning of the passphrase.
  219. #                      
  220. #                       Required?                                       false
  221. #                       Position?                                       2
  222. #                       Default value                           0
  223. #                       Accept pipeline input?          true
  224. #                       Accept wildcard characters?     false
  225. #                      
  226. #       .PARAMETER -NumbersAfter [<int>]
  227. #                       Specifies the number of random digits to place at the end of the passphrase.
  228. #                      
  229. #                       Required?                                       false
  230. #                       Position?                                       3
  231. #                       Default value                           4
  232. #                       Accept pipeline input?          true
  233. #                       Accept wildcard characters?     false
  234. #                      
  235. #       .PARAMETER -SymbolsBefore [<int>]
  236. #                       Specifies the number of symbols to place at the beginning of the passphrase.
  237. #                      
  238. #                       Required?                                       false
  239. #                       Position?                                       4
  240. #                       Default value                           0
  241. #                       Accept pipeline input?          true
  242. #                       Accept wildcard characters?     false
  243. #                      
  244. #       .PARAMETER -SymbolsAfter [<int>]
  245. #                       Specifies the number of symbols to place at the end of the passphrase.
  246. #                      
  247. #                       Required?                                       false
  248. #                       Position?                                       5
  249. #                       Default value                           0
  250. #                       Accept pipeline input?          true
  251. #                       Accept wildcard characters?     false
  252. #                      
  253. #       .PARAMETER -PadTo [<int>]
  254. #                       Specifies the number of padding symbols to place at the end of the passphrase. If no padding symbol is specified with the
  255. #                       -PadSymbol parameter, a random symbol from keyboard-printable characters will be chosen.
  256. #                      
  257. #                       Required?                                       false
  258. #                       Position?                                       6
  259. #                       Default value                           0
  260. #                       Accept pipeline input?          true
  261. #                       Accept wildcard characters?     false
  262. #                      
  263. #       .PARAMETER -Case [<string>]
  264. #                       Specifies the case of the words in the passphrase. Valid selections are:  Alternating, InvertTitleCase, LowerCase, Random,
  265. #                       TitleCase, and UpperCase
  266. #                      
  267. #                       Required?                                       false
  268. #                       Position?                                       7
  269. #                       Default value                           Alternating
  270. #                       Accept pipeline input?          true
  271. #                       Accept wildcard characters?     false
  272. #                      
  273. #       .PARAMETER -Separator [<string>]
  274. #                       Specifies the separator symbol to use in the passphrase. All keyboard-printable characters, space, and null are valid.
  275. #                       If not set, a random symbol from non-null keyboard-printable characters (including space) will be chosen as the separator.
  276. #                      
  277. #                       Required?                                       false
  278. #                       Position?                                       8
  279. #                       Default value                           <Random Symbol>
  280. #                       Accept pipeline input?          true
  281. #                       Accept wildcard characters?     false
  282. #                      
  283. #       .PARAMETER -PadSymbol [<string>]
  284. #                       Specifies the padding symbol to place at the end of the passphrase. Parameter is only used if the -PadTo parameter has
  285. #                       been specified. If the -PadTo parameter is specified but the -PadSymbol parameter is not specified, a random symbol
  286. #                       from non-null, non-space, keyboard-printable characters will be chosen as the padding symbol.
  287. #                      
  288. #                       Required?                                       false
  289. #                       Position?                                       9
  290. #                       Default value                           <Random Symbol>
  291. #                       Accept pipeline input?          true
  292. #                       Accept wildcard characters?     false
  293. #                      
  294. #       .PARAMETER -Generate [<int>]
  295. #                       Specifies the number of passphrases to generate. All passphrases generated will comply with the parameters set.
  296. #                      
  297. #                       Required?                                       false
  298. #                       Position?                                       10
  299. #                       Default value                           1
  300. #                       Accept pipeline input?          true
  301. #                       Accept wildcard characters?     false
  302. #              
  303. #       .PARAMETER -RandomLen [<switch>]
  304. #                       Specifies random word length. If this switch is set, the WordLength parameter is ignored.
  305. #                      
  306. #                       Required?                                       false
  307. #                       Position?                                       11
  308. #                       Default value                           false
  309. #                       Accept pipeline input?          true
  310. #                       Accept wildcard characters?     false
  311. #              
  312. #       .PARAMETER -MinLen [<int>]
  313. #                       Used with the RandomLen switch. Specifies the minimum length of the words used in the passphrase. If the RandomLen
  314. #                       switch is not set, this parameter does nothing.
  315. #                      
  316. #                       Required?                                       false
  317. #                       Position?                                       12
  318. #                       Default value                           4
  319. #                       Accept pipeline input?          true
  320. #                       Accept wildcard characters?     false
  321. #              
  322. #       .PARAMETER -MaxLen [<int>]
  323. #                       Used with the RandomLen switch. Specifies the maximum length of the words used in the passphrase. If the RandomLen
  324. #                       switch is not set, this parameter does nothing.
  325. #                      
  326. #                       Required?                                       false
  327. #                       Position?                                       13
  328. #                       Default value                           12
  329. #                       Accept pipeline input?          true
  330. #                       Accept wildcard characters?     false
  331. #              
  332. #       .EXAMPLE
  333. #               New-PassPhrase
  334. #      
  335. #               Description
  336. #               -----------
  337. #               Generates a random passphrase using the default parameters
  338. #
  339. #       .EXAMPLE
  340. #               New-PassPrase -Words 2 -WordLength 8 -SymbolsBefore 3 -Case Alternating -Generate 6
  341. #
  342. #               Description
  343. #               -----------
  344. #               Generates 6 passphrases with 2 random words that are each 8-characters long in alternating case. The passphrase will
  345. #               also have 3 identical but randomly-selected symbols prepended to it.
  346. #
  347. #       .EXAMPLE
  348. #               New-PassPhrase -Words 3 -WordLength 4 -PadTo 50 -PadSymbol "|"
  349. #
  350. #               Description
  351. #               -----------
  352. #               Generates a passphrase with 3 words that are each 4-characters long. The passphrase will be padded up to 50 characters
  353. #               with the | (pipe) symbol appended at the end.
  354. #
  355. #       .EXAMPLE
  356. #               New-PassPhrase -Words 4 -NumbersAfter 6 -Case Random -Separator "#" -Generate 20
  357. #
  358. #               Description
  359. #               -----------
  360. #               Generates 20 passphrases each with 4 words of random lengths and capitalization separated by the # (hash) symbol.
  361. #               The passphrase will end with 6 random digits.
  362. #
  363. #       .EXAMPLE
  364. #               New-PassPhrase -Words 2 -Case LowerCase -NumbersBefore 2 -NumbersAfter 2 -SymbolsBefore 2 -SymbolsAfter 2 -PadTo 100 -Generate 10
  365. #
  366. #               Description
  367. #               -----------
  368. #               Generates 10 passphrases with 2 random words of random length in all lowercase. The passphrases will be prepended
  369. #               by 2 random digits and 2 random symbols. The passphrases will also be appended with 2 random digits and 2 random
  370. #               symbols. The passphrases will be padded to 100 characters with a random symbol.
  371. #
  372. #       .EXAMPLE
  373. #               New-PassPhrase 3 8 0 4 0 2 50 Alternating "+" "%" 5
  374. #
  375. #               Description
  376. #               -----------
  377. #               Generates 5 passphrases with 3 words that are each 8-characters long and are in alternating case separated by the
  378. #               plus symbol. The passphrases will be appended with 4 random digits, 2 random symbols, and will also be padded to 50
  379. #               characters with the % (percent) symbol.
  380. #
  381. #       .EXAMPLE
  382. #               New-PassPhrase -Words 4 -RandomLen -MinLen 6 -MaxLen 10 -Generate 5
  383. #
  384. #               Description
  385. #               -----------
  386. #               Generates 5 passphrases with 4 words that are each between 6 and 10 characters long. A random separator character
  387. #               will be selected and the pass phrase will be appended with 4 random digits--based on default settings.
  388. #
  389. #
  390.  
  391. [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
  392. param(
  393.         [parameter(Mandatory = $false, Position = 0)]
  394.         [ValidateRange(1,([int]::MaxValue))][int]$Words = 4,
  395.         [parameter(Mandatory = $false, Position = 1)]
  396.         [ValidateRange(1,([int]::MaxValue))][int]$WordLength = 0,
  397.         [parameter(Mandatory = $false, Position = 2)]
  398.         [ValidateRange(0,([int]::MaxValue))][int]$NumbersBefore = 0,
  399.         [parameter(Mandatory = $false, Position = 3)]
  400.         [ValidateRange(0,([int]::MaxValue))][int]$NumbersAfter = 4,
  401.         [parameter(Mandatory = $false, Position = 4)]
  402.         [ValidateRange(0,([int]::MaxValue))][int]$SymbolsBefore = 0,
  403.         [parameter(Mandatory = $false, Position = 5)]
  404.         [ValidateRange(0,([int]::MaxValue))][int]$SymbolsAfter = 0,
  405.         [parameter(Mandatory = $false, Position = 6)]
  406.         [ValidateRange(0,([int]::MaxValue))][int]$PadTo = 0,
  407.         [parameter(Mandatory = $false, Position = 7)]
  408.         [ValidateSet("Alternating","InvertTitleCase","LowerCase","Random","TitleCase","UpperCase")][string]$Case = "Alternating",
  409.         [parameter(Mandatory = $false, Position = 8)]
  410.         [ValidateSet("~","!","@","#","$","%","^","&","*","-","_","=","+",";",":",",",".","\","|","/"," ","(",")","[","]","{","}","<",">","?",$null)]
  411.         [string]$Separator = (Get-Random -Input ("~","!","@","#","$","%","^","&","*","-","_","=","+",";",":",",",".","|"," ")),
  412.         [parameter(Mandatory = $false, Position = 9)]
  413.         [ValidateSet("~","!","@","#","$","%","^","&","*","-","_","=","+",";",":",",",".","\","|","/"," ","(",")","[","]","{","}","<",">","?")]
  414.         [string]$PadSymbol = (Get-Random -Input ("~","!","@","#","$","%","^","&","*","-","_","=","+",";",":",",",".","|")),
  415.         [parameter(Mandatory = $false, Position = 10)]
  416.         [ValidateRange(1,([int]::MaxValue))][int]$Generate = 1,
  417.         [parameter(Mandatory = $false, Position = 11)]
  418.         [switch]$RandomLen = $false,
  419.         [parameter(Mandatory = $false, Position = 12)]
  420.         [ValidateRange(4,([int]::MaxValue))][int]$MinLen = 4,
  421.         [parameter(Mandatory = $false, Position = 13)]
  422.         [ValidateScript({
  423.                 if($_ -lt $MinLen){
  424.                         throw 'MaxLen value cannot be less than MinLen value.'
  425.                 } $true
  426.         })][int]$MaxLen = 8
  427. )
  428.  
  429.         If ($WordLength -ne 0){
  430.                 $PList = (Import-CSV $PasswdList.Location | Where { $_.Word.Length -eq $WordLength})
  431.         }else{
  432.                 $PList = (Import-CSV $PasswdList.Location)
  433.         }
  434.        
  435.         If ($RandomLen -eq $true){
  436.                 $PList = (Import-CSV $PasswdList.Location | Where { $_.Word.Length -ge $MinLen -AND $_.Word.Length -le $MaxLen})
  437.         }
  438.  
  439.  
  440.         For($i=0;$i -lt $Generate;$i++){
  441.  
  442.                 $bSY = 0
  443.                 While($bSY -lt $SymbolsBefore){
  444.                         [string]$Word += $PadSymbol
  445.                         $bSY += 1
  446.                 }
  447.  
  448.                 $bNC = 0
  449.                 While($bNC -lt $NumbersBefore){
  450.                         [string]$Word += Get-Random -Minimum 0 -Maximum 10
  451.                         If($bNC -eq ($NumbersBefore - 1) -AND $bNC -gt 0){
  452.                                 [string]$Word += $Separator
  453.                         }
  454.                         $bNC += 1
  455.                 }
  456.  
  457.                 $WC = 0
  458.                 While($WC -lt $Words){
  459.  
  460.                 $WordLength =  Get-Random -Minimum $MinLen -Maximum ($MaxLen+1)
  461.                
  462.                         If($Case -eq "Random"){
  463.                                 $Rand = (Get-Random -Minimum 0 -Maximum 100)
  464.                
  465.                                 If((Compare-Even $Rand) -eq $True){
  466.                                         [string]$Word += ($(Get-Random -Input $PList).Word).ToUpper()
  467.                                         $WC += 1
  468.                                 }elseIf((Compare-Even $Rand) -eq $False){
  469.                                         [string]$Word += ($(Get-Random -Input $PList).Word).ToLower()
  470.                                         $WC += 1
  471.                                 }
  472.                                 If($WC -ne $Words){
  473.                                         [string]$Word += $Separator}
  474.  
  475.                         }elseIf($Case -eq "Alternating"){
  476.  
  477.                                 If((Compare-Even $WC) -eq $True){
  478.                                         [string]$Word += ($(Get-Random -Input $PList).Word).ToUpper()
  479.                                         $WC += 1
  480.                                 }elseIf((Compare-Even $WC) -eq $False){
  481.                                         [string]$Word += ($(Get-Random -Input $PList).Word).ToLower()
  482.                                         $WC += 1
  483.                                 }
  484.                                 If($WC -ne $Words){
  485.                                         [string]$Word += $Separator}
  486.                                
  487.                         }elseIf($Case -eq "LowerCase"){
  488.                                         [string]$Word += ($(Get-Random -Input $PList).Word).ToLower()
  489.                                         $WC += 1
  490.                                 If($WC -ne $Words){
  491.                                         [string]$Word += $Separator}
  492.                                
  493.                         }elseIf($Case -eq "UpperCase"){
  494.                                         [string]$Word += ($(Get-Random -Input $PList).Word).ToUpper()
  495.                                         $WC += 1
  496.                                 If($WC -ne $Words){
  497.                                         [string]$Word += $Separator}
  498.                         }elseIf($Case -eq "TitleCase"){
  499.                                         [string]$Word += (Get-Culture).TextInfo.ToTitleCase($(Get-Random -Input $PList).Word)
  500.                                         $WC += 1
  501.                                 If($WC -ne $Words){
  502.                                         [string]$word += $Separator}
  503.                         }elseIf($Case -eq "InvertTitleCase"){
  504.                                         [string]$Word += -join (((Get-Culture).TextInfo.ToTitleCase(($(Get-Random -Input $PList).Word))).ToCharArray() | %{[char]([int][char]$_ -bxor 0x20)})
  505.                                         $WC += 1
  506.                                 If($WC -ne $Words){
  507.                                         [string]$word += $Separator}
  508.                         }
  509.                 }
  510.  
  511.                 $eNC = 0
  512.                 If($Words -eq 0){[string]$Word += ""}
  513.                 While($eNC -lt $NumbersAfter){
  514.                         If($eNC -eq 0){
  515.                                 [string]$Word += $Separator}
  516.                         [string]$Word += Get-Random -Minimum 0 -Maximum 10
  517.                         $eNC += 1
  518.                 }
  519.  
  520.                 $eSY = 0
  521.                 While($eSY -lt $SymbolsAfter){
  522.                         [string]$Word += $PadSymbol
  523.                         $eSY += 1
  524.                 }
  525.                
  526.                 $Pad = 0
  527.                 $WL = 0
  528.                 [int]$WL = $Word.length
  529.                 If($WL -lt $PadTo){
  530.                         $Pad = ($PadTo - $WL)
  531.                 }
  532.                 While($WL -lt $PadTo){
  533.                         [string]$Word += $PadSymbol
  534.                         [int]$WL = $Word.length
  535.                 }
  536.  
  537.                 Write-Host $Word.Length "char:  " -NoNewLine
  538.                 Write-Host $Word
  539.                 Remove-Variable Word
  540.                
  541.                 If($Generate -gt 1){
  542.                         If(!$PSBoundParameters.ContainsKey('Separator')){
  543.                                 [string]$Separator = (Get-Random -Input ("~","!","@","#","$","%","^","&","*","-","_","=","+",";",":",",",".","|"," "))
  544.                         }
  545.                         If(!$PSBoundParameters.ContainsKey('PadSymbol')){
  546.                                 [string]$PadSymbol = (Get-Random -Input ("~","!","@","#","$","%","^","&","*","-","_","=","+",";",":",",",".","|"))
  547.                         }
  548.                 }
  549.         }
  550. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me