{"id":2374,"date":"2013-12-21T00:01:00","date_gmt":"2013-12-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/12\/21\/twas-the-night-of-before-scripting-part-1\/"},"modified":"2013-12-21T00:01:00","modified_gmt":"2013-12-21T00:01:00","slug":"twas-the-night-of-before-scripting-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/twas-the-night-of-before-scripting-part-1\/","title":{"rendered":"&#8216;Twas the Night of Before Scripting: Part 1"},"content":{"rendered":"<p><strong>Summary<\/strong>: &nbsp;Dr. Scripto teaches a non-scripting Administrator to easily create users in Active Directory.<\/p>\n<p align=\"left\">Microsoft Scripting Guy, Ed Wilson, here. Returning once again to delight us all with a little holiday merriment is Honorary Scripting Guy, Sean Kearney. Other than his habit of occasionally singing off-key Windows PowerShell music, he has taken on the challenge of writing an annual holiday Hey, Scripting Guy! Blog special.<\/p>\n<ul>\n<li align=\"left\">He started with <a href=\"\/b\/heyscriptingguy\/archive\/2010\/12\/21\/a-windows-powershell-carol-ebenezer-script-integrates-with-vbscript.aspx\" target=\"_blank\">A Windows PowerShell Carol: Ebenezer Script Integrates with VBScript<\/a>.<\/li>\n<li align=\"left\">The following year, we visited all of the Blues in Bluesville, where Mr. Finch learned scripting in <a href=\"\/b\/heyscriptingguy\/archive\/2011\/12\/19\/use-powershell-to-find-and-unlock-users-in-active-directory.aspx\" target=\"_blank\">Use PowerShell to Find and Unlock Users in Active Directory<\/a>.<\/li>\n<li align=\"left\">Last December we had to opportunity to visit the wonder with George Shelley in <a href=\"\/b\/heyscriptingguy\/archive\/2012\/12\/21\/it-s-a-wonderful-shell-chapter-1.aspx\" target=\"_blank\">It&rsquo;s a Wonderful Shell<\/a>.<\/li>\n<\/ul>\n<p align=\"left\">This year, the Scripting Guys proudly present to you in 3-D PowerShell-O-Rama Vision, the latest holiday edition. But before you rush to read today&rsquo;s post, see Sean&rsquo;s latest video: <a href=\"https:\/\/www.youtube.com\/watch?v=v8XuDXyt9YE&amp;feature=share&amp;list=UUQwtf2q4LnSyoVh4TNYFoNw\" target=\"_blank\">Just Script It<\/a>!<\/p>\n<p>&lsquo;Twas the night before scripting,<\/p>\n<p>A place of deep sorrow,<\/p>\n<p>An Admin sat crying,<\/p>\n<p>Not seeing tomorrow.<\/p>\n<p>&nbsp;<\/p>\n<p>A project was dropped onto him,<\/p>\n<p>Unfathomable in size,<\/p>\n<p>Impossible to scope,<\/p>\n<p>As he looked to the skies.<\/p>\n<p>&nbsp;<\/p>\n<p>Management undercommitted,<\/p>\n<p>And sales oversold,<\/p>\n<p>To gain this holiday contract,<\/p>\n<p>How were they so bold?<\/p>\n<p>&nbsp;<\/p>\n<p>The tasks of the project<\/p>\n<p>Placed before he<\/p>\n<p>Were four tasks that must done<\/p>\n<p>With consistency.<\/p>\n<p>&nbsp;<\/p>\n<p>And our good friend,<\/p>\n<p>A person like you,<\/p>\n<p>Had never learned to script,<\/p>\n<p>Oh yes, this was true.<\/p>\n<p>&nbsp;<\/p>\n<p>Our good fellow, he cried.<\/p>\n<p>Tears rolled to the floor<\/p>\n<p>As he stared to the distance,<\/p>\n<p>At the darkness of the door.<\/p>\n<p>&nbsp;<\/p>\n<p>With very little time,<\/p>\n<p>Just four days, you see,<\/p>\n<p>He was to complete these tasks,<\/p>\n<p>Finish them to a tee.<\/p>\n<p>&nbsp;<\/p>\n<p>This meant all day at work,<\/p>\n<p>No sleep at all,<\/p>\n<p>No smile from his wife,<\/p>\n<p>No hugs at all.<\/p>\n<p>&nbsp;<\/p>\n<p>These tasks, you wonder,<\/p>\n<p>Just bad, they were?<\/p>\n<p>I will tell you now<\/p>\n<p>To ruffle your fur.<\/p>\n<p>&nbsp;<\/p>\n<p>Remember a time,<\/p>\n<p>Far long ago,<\/p>\n<p>When you could not script,<\/p>\n<p>And now you will know.<\/p>\n<p>&nbsp;<\/p>\n<p>Today he would start<\/p>\n<p>With the first task at hand,<\/p>\n<p>Create some users<\/p>\n<p>Within his new land.<\/p>\n<p>&nbsp;<\/p>\n<p>Populate a new Active Directory<\/p>\n<p>With five hundred or so<\/p>\n<p>User accounts (details included),<\/p>\n<p>Addresses and mo&rsquo;.<\/p>\n<p>&nbsp;<\/p>\n<p>How the tears, they welled<\/p>\n<p>Into the keyboard below,<\/p>\n<p>Sparking and smoking,<\/p>\n<p>Like electrical snow.<\/p>\n<p>&nbsp;<\/p>\n<p>When out of the room,<\/p>\n<p>He heard a small voice,<\/p>\n<p>Like a tiny digital mouse,<\/p>\n<p>It was oddball, by choice,<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;My friend, I can see,&rdquo;<\/p>\n<p>Said a voice far below,<\/p>\n<p>Bespectled and kind,<\/p>\n<p>Was good Dr. Scripto!<\/p>\n<p>&nbsp;<\/p>\n<p>A wreath of deep green,<\/p>\n<p>Barely eight inches tall,<\/p>\n<p>As white as a December<\/p>\n<p>Massive snowfall.<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;I&rsquo;ll show you how,<\/p>\n<p>With no effort, you see,<\/p>\n<p>To use PowerShell to solve<\/p>\n<p>Your problems with glee.&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>So Dr. Scripto looked at<\/p>\n<p>The first task on the plate,<\/p>\n<p>&ldquo;We&rsquo;ll have this done<\/p>\n<p>Before it is late.&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>The Good Doctor then looked<\/p>\n<p>At the data below,<\/p>\n<p>A spreadsheet called Users.csv<\/p>\n<p>With columns to show:<\/p>\n<\/p>\n<p style=\"margin-left:30px\">FirstName,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastName,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UserAccount,&nbsp;&nbsp;&nbsp;&nbsp; Address,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thevoice,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16 A Place,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ottawa,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON<\/p>\n<p style=\"margin-left:30px\">Ford,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prefect, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; towelguy,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Beleljuice Lane,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Atlanta,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GA<\/p>\n<\/p>\n<p>&ldquo;Typing would be slow, a pain,<\/p>\n<p>And monotonous to do.<\/p>\n<p>I&rsquo;ll show you a line<\/p>\n<p>In PowerShell to do.&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>First, he laid out<\/p>\n<p>Some lines on the screen,<\/p>\n<p>&ldquo;This will give us our users,<\/p>\n<p>And do it all clean.&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">$Users=IMPORT-CSV<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;Now we&rsquo;ll access their names,<\/p>\n<p>Without overload,<\/p>\n<p>With just a few lines,<\/p>\n<p>Some tiny little code:&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">Foreach($User in $Users)<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">$First=$User.Firstname<\/p>\n<p style=\"margin-left:30px\">$Last=$User.Lastname<\/p>\n<p style=\"margin-left:30px\">$Acct=$User.UserAccount<\/p>\n<p style=\"margin-left:30px\">$Addr=$User.Address<\/p>\n<p style=\"margin-left:30px\">$City=$User.City<\/p>\n<p style=\"margin-left:30px\">$State=$User.St<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>&nbsp;<\/p>\n<p>All of the information<\/p>\n<p>Scrolled right by his eyes,<\/p>\n<p>Much to the amazement<\/p>\n<p>And delight of his eyes.<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;A password, we&rsquo;ll build,<\/p>\n<p>Simple and sweet,<\/p>\n<p>And the UPN for AD,<\/p>\n<p>So the credentials will meet:&rdquo;<\/p>\n<\/p>\n<p style=\"margin-left:30px\">$TempPassword=(CONVERTTO-SecureString &ndash;asplaintext &ndash;force &ndash;string &lsquo;TempPassword1&rsquo;<\/p>\n<p style=\"margin-left:30px\">$DomainUPN=&rsquo;@Contoso.local&rsquo;<\/p>\n<\/p>\n<p>&ldquo;Now to finish it all,<\/p>\n<p>A cmdlet we&rsquo;ll use,<\/p>\n<p>Called New-ADUser,<\/p>\n<p>Not a magical ruse:&rdquo;<\/p>\n<\/p>\n<p style=\"margin-left:30px\">Foreach($User in $Users)<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">$First=$User.Firstname<\/p>\n<p style=\"margin-left:30px\">$Last=$User.Lastname<\/p>\n<p style=\"margin-left:30px\">$Acct=$User.UserAccount<\/p>\n<p style=\"margin-left:30px\">$Addr=$User.Address<\/p>\n<p style=\"margin-left:30px\">$City=$User.City<\/p>\n<p style=\"margin-left:30px\">$State=$User.St<\/p>\n<p style=\"margin-left:30px\">$TempPassword=(CONVERTTO-SecureString &ndash;asplaintext &ndash;force &ndash;string &lsquo;TempPassword1&rsquo;)<\/p>\n<p style=\"margin-left:30px\">$DomainUPN=$Acct+&rsquo;@Contoso.local&rsquo;<\/p>\n<p style=\"margin-left:30px\">NEW-ADUSER $Acct &ndash;GivenName $First &ndash;Surname $Last &ndash;StreetAddress $Addr &ndash;City $City &ndash;State $State <br \/>&ndash;UserPrincipalName $DomainUPN &ndash;AccountPassword $TempPassword<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<\/p>\n<p>&ldquo;To a file, we&rsquo;ll save this,<\/p>\n<p>Call it NEWUSERS.PS1,<\/p>\n<p>Now we start it in PowerShell,<\/p>\n<p>And have us some fun:&rdquo;<\/p>\n<\/p>\n<p style=\"margin-left:30px\">.\\NEWUSERS.PS1<\/p>\n<p style=\"margin-left:30px\">\n<p>In a short span of minutes,<\/p>\n<p>Not even time to go click,<\/p>\n<p>The Admin pulled up his list,<\/p>\n<p>And saw users appear so quick:<\/p>\n<p style=\"margin-left:30px\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1.png\" alt=\"Image of list\" title=\"Image of list\" \/><\/a><\/p>\n<p>Our Admin friend paused,<\/p>\n<p>And a smile came free,<\/p>\n<p>Perhaps there was hope?<\/p>\n<p>For that, he would see&hellip;<\/p>\n<p>Come back tomorrow and we&rsquo;ll see just how much Dr. Scripto can help our good non-scripting friend. Perhaps he will see the holidays? You&rsquo;ll know before the end.<\/p>\n<p>~Sean<\/p>\n<p>I invite you to follow the Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Sean Kearney<\/strong>, <br \/>Honorary Scripting Guy and&nbsp;Windows PowerShell MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: &nbsp;Dr. Scripto teaches a non-scripting Administrator to easily create users in Active Directory. Microsoft Scripting Guy, Ed Wilson, here. Returning once again to delight us all with a little holiday merriment is Honorary Scripting Guy, Sean Kearney. Other than his habit of occasionally singing off-key Windows PowerShell music, he has taken on the challenge [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,154,45],"class_list":["post-2374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: &nbsp;Dr. Scripto teaches a non-scripting Administrator to easily create users in Active Directory. Microsoft Scripting Guy, Ed Wilson, here. Returning once again to delight us all with a little holiday merriment is Honorary Scripting Guy, Sean Kearney. Other than his habit of occasionally singing off-key Windows PowerShell music, he has taken on the challenge [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2374"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}