Get random passwords

As part of my daily operations tasks, I have sometimes to create random passwords for a new series of computers to be integrated in the domain.

Precisely, I have to create a list of computers and their random 10 characters long passwords that mixes upper and lower case letters compatible with a qwerty and azerty keyboard layout and that doesn’t match a word in a dictionary. The computer names and passwords should be tab separated so that it could be appended to our global passwords file a.xls in order to be readable in Excel (if necessary). Using a tab separated file also allows us to use this file in a scripted manner. It’s being parsed by a central custom script that checks if the password didn’t change on a daily basis.

So here’s the result of my quick and dirty approach for computer names from PTV800 to PTV899.

# Get a list of characters
$list = [Char[]]'bcdefhijklnoprstuvxBCDEFHIJKLNOPRSTUVX'

# Loop 
0..99 | % {
 # Get a 10 characters long random password where each characters is picked up from our list of characters
 $pw = (-join (1..10 | Foreach-Object { Get-Random $list -count 1 }))
 # Build our computername matching our naming convention
 $pcname = "PTV8" + ("{0:00}" -f $_)
 Write-Host -Object ($pcname + "`t" + $pw)
 # Append to our global tab separated file
 Write-Output -InputObject ($pcname + "`t" + $pw)  | Out-File -filepath .\a.xls -Append -NoClobber -Encoding ASCII
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s