With PowerShell creating passwords is fairly easy. Depending on how random you want your password you might never remember it. Today we will walk you through randomly generate a passphrase using PowerShell. The more and more complex each password we create gets the harder it is to remember the password. That is where a passphrase helps.
Something that is much easier to remember is a phrase than a random set of characters, letters and numbers. With a passphrase it becomes a bit more easy to remember said password while also making it incredibly more complex for anyone with nefarious intentions to crack the passphrase. Let’s get into creating this function.
The fun part for me is working with an array. In writing this I have added almost 1000 words to this. Now, I am not going to post the entire array for this project, however I will give you a great starting point and you can add as many as you like. To start I created a variable named $namelist. I know original. It looks like so:
$namelist ='a','ability','able','about','above','accept','according','account','across','act','action','activity','actually','add','address','administration','admit','adult','affect','after','again','against','age','agency','agent','ago','agree','agreement','ahead','air','all','allow','almost','alone','along','already','also','although','always','American','among'
Above is the $namelist array. This is a great starting point. We want to use all of the words in the array to build a passphrase, but we do not want to use them all at one time. To start I link a new variable $last to $namelist. That looks like this:
$last = $namelist
That takes the array stored in $namelist, and copies it to $last. Now we need to take $last and work with it. To start we pipe the variable $last to get-random. Let’s see how I did it, then I can explain it.
| get-random -SetSeed (Get-Date).Ticks.ToString().Substring(10) -count 5
Alright.. wait what? Using Get-Date to Get-Random? Haha, yes that is right. For instance, when you use Get-Random it is not very random. In fact out of 10 random runs using Get-Random “vanella”, you will get around 4-6 near-duplicates. So what we do here is use (Get-Date).Ticks then output .ToString(), and start on the 10th place in the (Get-Date).Ticks array data.
In addition when you Get-Date you get back all of the following data.
PS U:\> get-date | Format-List DisplayHint : DateTime Date : 3/8/2021 12:00:00 AM Day : 8 DayOfWeek : Monday DayOfYear : 67 Hour : 16 Kind : Local Millisecond : 722 Minute : 15 Month : 3 Second : 19 Ticks : 637508169197223740 TimeOfDay : 16:15:19.7223740 Year : 2021 DateTime : Monday, March 8, 2021 4:15:19 PM
As you can see above, the Ticks property is unique. Moreover, it is unique every time you run the get-date command. That makes it a perfect use case for a seed when using Get-Random to add a bit more randomness to the command. At the end we use a -count 5 that says grab only five array elements, no more. In this case would be five words.
$last = [system.String]::Join(" ", $last)
The above line takes the $last variable, now with five words in it, and joins all of the words together leaving a space. Prior to doing this the output would look similar to this for one passphrase.
1..5 | Foreach {get-phraseology} nature smile third science sexual nor recent choose doctor legal west whole finger describe citizen cancer event make send general deep table analysis parent just
As a result, this is not helpful. That is why we join with a space between the words.
$last
Most importantly, we output the $last variable to the console. That way we provide you with your newly created passphrases.
What’s it all look like in a reusable function? I am glad you asked! Here’s the entire script with all the words, so far.
Function Get-Phraseology { $namelist ='a','ability','able','about','above','accept','according','account','across','act','action','activity','actually','add','address','administration','admit','adult','affect','after','again','against','age','agency','agent','ago','agree','agreement','ahead','air','all','allow','almost','alone','along','already','also','although','always','American','among','amount','analysis','and','animal','another','answer','any','anyone','anything','appear','apply','approach','area','argue','arm','around','arrive','art','article','artist','as','ask','assume','at','attack','attention','attorney','audience','author','authority','available','avoid','away','baby','back','bad','bag','ball','bank','bar','base','be','beat','beautiful','because','become','bed','before','begin','behavior','behind','believe','benefit','best','better','between','beyond','big','bill','billion','bit','black','blood','blue','board','body','book','born','both','box','boy','break','bring','brother','budget','build','building','business','but','buy','by','call','camera','campaign','can','cancer','candidate','capital','car','card','care','career','carry','case','catch','cause','cell','center','central','century','certain','certainly','chair','challenge','chance','change','character','charge','check','child','choice','choose','church','citizen','city','civil','claim','class','clear','clearly','close','coach','cold','collection','college','color','come','commercial','common','community','company','compare','computer','concern','condition','conference','Congress','consider','consumer','contain','continue','control','cost','could','country','couple','course','court','cover','create','crime','cultural','culture','cup','current','customer','cut','dark','data','daughter','day','dead','deal','death','debate','decade','decide','decision','deep','defense','degree','Democrat','democratic','describe','design','despite','detail','determine','develop','development','die','difference','different','difficult','dinner','direction','director','discover','discuss','discussion','disease','do','doctor','dog','door','down','draw','dream','drive','drop','drug','during','each','early','east','easy','eat','economic','economy','edge','education','effect','effort','eight','either','election','else','employee','end','energy','enjoy','enough','enter','entire','environment','environmental','especially','establish','even','evening','event','ever','every','everybody','everyone','everything','evidence','exactly','example','executive','exist','expect','experience','expert','explain','eye','face','fact','factor','fail','fall','family','far','fast','father','fear','federal','feel','feeling','few','field','fight','figure','fill','film','final','finally','financial','find','fine','finger','finish','fire','firm','first','fish','five','floor','fly','focus','follow','food','foot','for','force','foreign','forget','form','former','forward','four','free','friend','from','front','full','fund','future','game','garden','gas','general','generation','get','girl','give','glass','go','goal','good','government','great','green','ground','group','grow','growth','guess','gun','guy','hair','half','hand','hang','happen','happy','hard','have','he','head','health','hear','heart','heat','heavy','help','her','here','herself','high','him','himself','his','history','hit','hold','home','hope','hospital','hot','hotel','hour','house','how','however','huge','human','hundred','husband','I','idea','identify','if','image','imagine','impact','important','improve','in','include','including','increase','indeed','indicate','individual','industry','information','inside','instead','institution','interest','interesting','international','interview','into','investment','involve','issue','it','item','its','itself','job','join','just','keep','key','kid','kill','kind','kitchen','know','knowledge','land','language','large','last','late','later','laugh','law','lawyer','lay','lead','leader','learn','least','leave','left','leg','legal','less','let','letter','level','lie','life','light','like','likely','line','list','listen','little','live','local','long','look','lose','loss','lot','love','low','machine','magazine','main','maintain','major','majority','make','man','manage','management','manager','many','market','marriage','material','matter','may','maybe','me','mean','measure','media','medical','meet','meeting','member','memory','mention','message','method','middle','might','military','million','mind','minute','miss','mission','model','modern','moment','money','month','more','morning','most','mother','mouth','move','movement','movie','Mr','Mrs','much','music','must','my','myself','name','nation','national','natural','nature','near','nearly','necessary','need','network','never','new','news','newspaper','next','nice','night','no','none','nor','north','not','note','nothing','notice','now','nown','number','occur','of','off','offer','office','officer','official','often','oh','oil','ok','old','on','once','one','only','onto','open','operation','opportunity','option','or','order','organization','other','others','our','out','outside','over','own','owner','page','pain','painting','paper','parent','part','participant','particular','particularly','partner','party','pass','past','patient','pattern','pay','peace','people','per','perform','performance','perhaps','period','person','personal','phone','physical','pick','picture','piece','place','plan','plant','play','player','PM','point','police','policy','political','politics','poor','popular','population','position','positive','possible','power','practice','prepare','present','president','pressure','pretty','prevent','price','private','probably','problem','process','produce','product','production','professional','professor','program','project','property','protect','prove','provide','public','pull','purpose','push','put','quality','question','quickly','quite','race','radio','raise','range','rate','rather','reach','read','ready','real','reality','realize','really','reason','receive','recent','recently','recognize','record','red','reduce','reflect','region','relate','relationship','religious','remain','remember','remove','report','represent','Republican','require','research','resource','respond','response','responsibility','rest','result','return','reveal','rich','right','rise','risk','road','rock','role','room','rule','run','safe','same','save','say','scene','school','science','scientist','score','sea','season','seat','second','section','security','see','seek','seem','sell','send','senior','sense','series','serious','serve','service','set','seven','several','sex','sexual','shake','share','she','shoot','short','shot','should','shoulder','show','side','sign','significant','similar','simple','simply','since','sing','single','sister','sit','site','situation','six','size','skill','skin','small','smile','so','social','society','soldier','some','somebody','someone','something','sometimes','son','song','soon','sort','sound','source','south','southern','space','speak','special','specific','speech','spend','sport','spring','staff','stage','stand','standard','star','start','state','statement','station','stay','step','still','stock','stop','store','story','strategy','street','strong','structure','student','study','stuff','style','subject','success','successful','such','suddenly','suffer','suggest','summer','support','sure','surface','system','table','take','talk','task','tax','teach','teacher','team','technology','television','tell','ten','tend','term','test','than','thank','that','the','their','them','themselves','then','theory','there','these','they','thing','think','third','this','those','though','thought','thousand','threat','three','through','throughout','throw','thus','time','to','today','together','tonight','too','top','total','tough','toward','town','trade','traditional','training','travel','treat','treatment','tree','trial','trip','trouble','truth','try','turn','TV','two','type','under','understand','unit','until','up','upon','us','use','usually','value','various','very','victim','view','violence','visit','voice','vote','wait','walk','wall','want','war','watch','water','way','we','weapon','wear','week','weight','well','west','western','what','whatever','when','where','whether','which','while','white','who','whole','whom','whose','why','wide','wife','will','win','wind','window','wish','with','within','without','woman','wonder','word','work','worker','world','worry','would','write','writer','wrong','yard','yeah','year','yes','yet','you','young','your','yourself' $last = $namelist | get-random -SetSeed (Get-Date).Ticks.ToString().Substring(10) -count 5 $last = [system.String]::Join(" ", $last) $last } 1..5 | Foreach {get-phraseology}
Output
1..5 | Foreach {get-phraseology} event bank during add sport Mrs skin your health popular early exist church everyone beautiful notice ask though writer it across speech activity financial college
If you liked this post check out some of our others below: