Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :
TheServerGeeks

IT with everything IT

[How To] PowerShell Password Generator

/

Have you ever had to create user accounts in active directory or for any other database for authentications? If yes, you may have the save concern as i do about security of that account. So, the first step to secure the account is to have the secure password.

Yes. I agree that you have multiple options to generate passwords through online websites or multiple different applications easily. But, have you ever wondered if you could do generate random passwords through PowerShell?

Well, let me tell you that its possible to do so. And if you have a question as to why do i need to do this from PowerShell when you have multiple different options to do this, Let me tell you. 

With the PowerShell, you could automate many things which you are doing on daily basis and reduce the manual work and increase the productivity.

If you want to know how to create bulk users in AD, click here to know more

So, Lets jump right in and create a password generator using Windows PowerShell. 

Considering that your password policy requires a minimum of 10 characters, and requires special characters, Numbers, and also Capital letters. 

Let’s have them created first in the PowerShell

$alphabets = ‘a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z’
$numbers = 0..9
$Specialcharacters = ‘~,!,@,#,$,%,^,&,*,(,),>,<,?,\,/,_,-,=,+’

Executing the above Cmdlets in PowerShell will create a Variables for Alphabets, Numbers, and Special Characters. and assign the values for them.

Let’s create an array of random characters by using the above variables

$array = @()
$array+= $alphabets .Split(‘,’) | Get-Random -Count 4
$array[0] = $array[0].ToUpper()
$array[-1] = $array[-1].ToUpper()
$array+= $numbers | Get-Random -Count 3
$array+= $Specialcharacters .Split(‘,’) | Get-Random -Count 3

Now in the above first 4 lines, I am selecting random 4 alphabets and and Capitalizing the first and last alphabets.
Then, on the 5th line, i am selecting random 3 numbers
on the 6th Line, i am selecting random 3 special characters

So now, we have 4 alphabets, 3 numbers, 3 special characters to make the 10 digit password. Now, let’s arrange all these and make the password.

($array | Get-Random -Count $arr.Count) -join “”

In this above line, I am selecting the random characters in the array, which has all the numbers, alphabets, and special characters and matching the count to be 10 and finally joining them. Let’s wrap up all these and create a PowerShell Script

$Alphabets = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'
$numbers = 0..9
$specialCharacters = '~,!,@,#,$,%,^,&,*,(,),>,<,?,\,/,_,-,=,+'
$array = @()
$array += $Alphabets.Split(',') | Get-Random -Count 4
$array[0] = $array[0].ToUpper()
$array[-1] = $array[-1].ToUpper()
$array += $numbers | Get-Random -Count 3
$array += $specialCharacters.Split(',') | Get-Random -Count 3
($array | Get-Random -Count $array.Count) -join ""

Copy the above codes and save in a .Ps1 file. and execute the script in PowerShell. Everytime you run this script, you get the new and strong password

In the next article, i will be showing you how to use the PowerShell script we have to Create AD accounts, and the script to Generate Password, and kind of automate this even further.

So, keep watching this site for more interesting contents.

2 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar