How to generate a strong password using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To generate a strong password with the PowerShell, we can use 8 or more characters password. In the below example, we are going to use the 8 character password, you can change the number of characters as per your convenience.

This script you can bind into windows forms and provide it to the IT helpdesk to set the password for new users.

In this example, we will use the Random integers between 33 and 126 and convert it to the Character, considering them they are the ASCII values for characters.

You can find more about ASCII values in the table provided in the link.

https://www.rapidtables.com/code/text/ascii-table.html

Now we will see the explanation of the script and then finally write the script.

To get the random numbers between 33 and 126, Get-Random command is used.

Get-Random -Minimum 33 -Maximum 126

Once, you get the number, translate it into character by type conversion.

[char](Get-Random -Minimum 33 -Maximum 126)

We have not a single character, but we need 8 characters long password so you need to loop above commands 8 times and append each character to the previous character.

Example

[int]$passlength = 8
[string]$pass
for($i=0; $i -lt $passlength; $i++){
   $pass += [char](Get-Random -Minimum 33 -Maximum 126)
}
$pass

Output

EGS)^&hf
raja
Published on 13-Jul-2020 05:38:41
Advertisements