{"id":2153,"date":"2016-06-13T13:18:16","date_gmt":"2016-06-13T12:18:16","guid":{"rendered":"http:\/\/emtunc.org\/blog\/?p=2153"},"modified":"2017-02-24T14:58:43","modified_gmt":"2017-02-24T14:58:43","slug":"random-password-generator-powershell","status":"publish","type":"post","link":"https:\/\/emtunc.org\/blog\/06\/2016\/random-password-generator-powershell\/","title":{"rendered":"Random Password Generator in PowerShell"},"content":{"rendered":"<p>Here is a quick and dirty PowerShell script that you can use to generate pseudo-random passwords using dictionary words, numbers and special characters.<\/p>\n<p>This kind of script is good for environments such as schools and universities where mass-enrolment is quite common before the start of the academic year.<\/p>\n<p>You can incorporate\u00a0the function in your own script or come up with something new.<\/p>\n<p>Credit goes to <a href=\"http:\/\/setgetgo.com\/\" target=\"_blank\">setgetgo.com<\/a>\u00a0for making the random word generator API available for public use.<\/p>\n<p>The code is available on\u00a0my <a href=\"https:\/\/github.com\/emtunc\/PowerShell-Pseudo-Random-Password-Generator\" target=\"_blank\">GitHub<\/a> page and is a good place to check for the latest iteration of code as well as some examples. Below is the code as of 14\/06\/2016<\/p>\n<pre class=\"lang:ps decode:true  \">&lt;#\r\n.SYNOPSIS\r\nGenerate a random password\r\n\r\n.DESCRIPTION\r\nUses the setgetgo.com random word API to generate random words. A random number and special character is then appended\r\n\r\n.PARAMETER numberOfPasswords\r\nNumber of passwords to generate. Default is 1.\r\n\r\n.PARAMETER wordLength\r\nWord length. Default is 8.\r\n\r\n.PARAMETER allowedSpecialCharacters\r\nSpecial characters that are allowed to be appended to the password. Default is ! * and ?\r\nIf defining your own, use the format:\r\nGenerate-Password -allowedSpecialCharacters \"!\",\"?\",\",\",\"\/\"\r\n\r\n.PARAMETER maximumNumber\r\nDefault number to append to word will be between 0 and 999.\r\n\r\n.EXAMPLE\r\nPS C:\\&gt; Generate-Password\r\nThis will generate a random 8 character word, append a number between 0 and 999 and finally append a special character.\r\n\r\n.NOTES\r\nAdditional information about the function.\r\n#&gt;\r\nfunction Generate-Password\r\n{\r\n[CmdletBinding()]\r\n[OutputType([string])]\r\nparam\r\n(\r\n[Parameter(Mandatory = $false)]\r\n[int]$numberOfPasswords = 1,\r\n[Parameter(Mandatory = $false)]\r\n[int]$wordLength = 8,\r\n[Parameter(Mandatory = $false)]\r\n$allowedSpecialCharacters = @('!', '*', '?'),\r\n[Parameter(Mandatory = $false)]\r\n[int]$maximumNumber = 999\r\n)\r\n\r\nfor ($i = 1; $i -le $numberOfPasswords; $i++)\r\n{\r\n$randomWord = Invoke-WebRequest -URI http:\/\/randomword.setgetgo.com\/get.php?len=$wordLength\r\n$randomNumber = Get-Random -Maximum $maximumNumber\r\n$randomSpecialCharacter = $allowedSpecialCharacters | Get-Random\r\nWrite-Output \"$($randomWord.content)$randomNumber$randomSpecialCharacter\"\r\n}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is a quick and dirty PowerShell script that you can use to generate pseudo-random passwords using dictionary words, numbers and special characters. This kind of script is good for environments such as schools and universities where mass-enrolment is quite common before the start of the academic year. You can incorporate\u00a0the function in your own [&hellip;]<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[1],"tags":[197,236,42],"class_list":["post-2153","post","type-post","status-publish","format-standard","hentry","category-tech","tag-github","tag-password","tag-powershell"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1trTO-yJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/comments?post=2153"}],"version-history":[{"count":8,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2153\/revisions"}],"predecessor-version":[{"id":2467,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2153\/revisions\/2467"}],"wp:attachment":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/media?parent=2153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/categories?post=2153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/tags?post=2153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}