{"id":2371,"date":"2013-12-22T00:01:00","date_gmt":"2013-12-22T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/12\/22\/twas-the-night-before-scripting-part-2\/"},"modified":"2013-12-22T00:01:00","modified_gmt":"2013-12-22T00:01:00","slug":"twas-the-night-before-scripting-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/twas-the-night-before-scripting-part-2\/","title":{"rendered":"&#8216;Twas the Night Before Scripting: Part 2"},"content":{"rendered":"<p><b>Summary<\/b>: Dr. Scripto helps an Admin learn how to easily modify custom attributes in Active Directory.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, here. If you missed it yesterday, 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>! Also be sure to read yesterday&rsquo;s post before you start on today&rsquo;s: <a href=\"\/b\/heyscriptingguy\/archive\/2013\/12\/21\/twas-the-night-of-before-scripting-part-1.aspx\" target=\"_blank\">&lsquo;Twas the Night of Before Scripting: Part 1<\/a>.<\/p>\n<p>Here&rsquo;s Sean&hellip;<\/p>\n<p>In yesterday&rsquo;s episode, we encountered an Administrator who was near tears due to the time constraints of a massive project and the bad timing of it occurring during the holidays. Magically from a spark of ozone, our good friend Dr. Scripto appeared to aid him. Today, we continue as he gains some further insight into Windows PowerShell and the power of automation.<\/p>\n<p>&nbsp;<\/p>\n<p>And so we continue,<\/p>\n<p>Much deeper to the night,<\/p>\n<p>The Admin who never scripted,<\/p>\n<p>And suddenly took fright.<\/p>\n<p>&nbsp;<\/p>\n<p>A project that would take<\/p>\n<p>All of the hours<\/p>\n<p>Of holiday time,<\/p>\n<p>And also no showers.<\/p>\n<p>&nbsp;<\/p>\n<p>But Dr. Scripto<\/p>\n<p>Appeared in time,<\/p>\n<p>In a sparking of ozone,<\/p>\n<p>And badly done rhyme.<\/p>\n<p>&nbsp;<\/p>\n<p>With PowerShell, they made<\/p>\n<p>Users (so many),<\/p>\n<p>And did it barely<\/p>\n<p>In the cost of a penny.<\/p>\n<p>&nbsp;<\/p>\n<p>But now, an email stirred<\/p>\n<p>To our good Admin friend,<\/p>\n<p>That made him just panic,<\/p>\n<p>Nearly to the end.<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;It&rsquo;s from the Boss.<\/p>\n<p>He insists that I quickly<\/p>\n<p>Update the field,<\/p>\n<p>With the raw Info account provided to me!&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>Oh, the panic in his eyes,<\/p>\n<p>and gasps of pure dread!<\/p>\n<p>To manually update over 500 staff&hellip;<\/p>\n<p>Fear crept to his head!<\/p>\n<p>&nbsp;<\/p>\n<p>But the good Doctor,<\/p>\n<p>With a twinkle in his eye,<\/p>\n<p>Smiled and said,<\/p>\n<p>&ldquo;We can solve this without try.&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;Let us take the first script,<\/p>\n<p>The one we used to make<\/p>\n<p>The staff of 500,<\/p>\n<p>We&rsquo;ll change it easy as cake.&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>So he copied it out,<\/p>\n<p>And pasted it back,<\/p>\n<p>The previous script,<\/p>\n<p>His small coding snack:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">$Users=IMPORT-CSV Users.csv<\/p>\n<p style=\"margin-left:30px\">&nbsp;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 &ndash;UserPrincipalName $DomainUPN &ndash;AccountPassword $TempPassword<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;One more cmdlet<\/p>\n<p>For this task we&rsquo;ll need,<\/p>\n<p>A simple cmdlet<\/p>\n<p>To aid in our deed.<\/p>\n<p>&nbsp;<\/p>\n<p>We do not need UPN<\/p>\n<p>Or a password this time,<\/p>\n<p>So we&rsquo;ll comment out<\/p>\n<p>All of those lines:&rdquo;<\/p>\n<p>&nbsp;<\/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>&nbsp;<\/p>\n<p>Our Admin blinked,<\/p>\n<p>And looked at the screen,<\/p>\n<p>Using the hash mark<\/p>\n<p>Would skip like a sheen.<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;We must now take info<\/p>\n<p>Provided us from file<\/p>\n<p>USER.CSV and<\/p>\n<p>Combine to a pile:&rdquo;<\/p>\n<p>&nbsp;<\/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\">$info=$First+&rdquo;,&rdquo;+$Last+&rdquo;,&rdquo;+$Acct+&rdquo;,&rdquo;+$Addr+&rdquo;,&rdquo;+$City+&rdquo;,&rdquo;+$State<\/p>\n<p>&nbsp;<\/p>\n<p>Our good friend, Scripto,<\/p>\n<p>Did then type to the screen,<\/p>\n<p>The cmdlet to use<\/p>\n<p>To aid in their mean:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">SET-ADUSER $Acct &ndash;replace @{info=$info}<\/p>\n<p>&nbsp;<\/p>\n<p>&ldquo;Ooops! I almost forgot<\/p>\n<p>To do one more thing!<\/p>\n<p>Comment out <b>New-ADUser<\/b>,<\/p>\n<p>And our script, it can sing!&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>And so he looked at<\/p>\n<p>The script he would run,<\/p>\n<p>And saved it as the new<\/p>\n<p>UPDATE.PS1:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">$Users=IMPORT-CSV Users.csv<\/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 &ndash;UserPrincipalName $DomainUPN &ndash;AccountPassword $TempPassword<\/p>\n<p style=\"margin-left:30px\">$info=$First+&rdquo;,&rdquo;+$Last+&rdquo;,&rdquo;+$Acct+&rdquo;,&rdquo;+$Addr+&rdquo;,&rdquo;+$City+&rdquo;,&rdquo;+$State<\/p>\n<p style=\"margin-left:30px\">SET-ADUSER $Acct &ndash;replace @{info=$info}<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>&nbsp;<\/p>\n<p>Running the script<\/p>\n<p>And checking AD<\/p>\n<p>Showed their User;<\/p>\n<p>They had done it correctly!<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/Capture%201.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/Capture%201.PNG\" border=\"0\" alt=\" \" \/><\/a><\/p>\n<p>Dr. Scripto looked up<\/p>\n<p>At his friend in the chair,<\/p>\n<p>&ldquo;Amazing what you can do<\/p>\n<p>With some PowerShell flair!&rdquo;<\/p>\n<p>&nbsp;<\/p>\n<p>The strain seemed to<\/p>\n<p>Pass from his face,<\/p>\n<p>Perhaps he might win<\/p>\n<p>In this mad deployment race?<\/p>\n<p>&nbsp;<\/p>\n<p>Pop in tomorrow as we watch further. Will our good Admin friend manage to find some way to complete all of his work in a reasonable time? Will he be home for the holidays?&nbsp; Only further reading will tell!<\/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&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Dr. Scripto helps an Admin learn how to easily modify custom attributes in Active Directory. Microsoft Scripting Guy, Ed Wilson, here. If you missed it yesterday, see Sean&rsquo;s latest video: Just Script It! Also be sure to read yesterday&rsquo;s post before you start on today&rsquo;s: &lsquo;Twas the Night of Before Scripting: Part 1. Here&rsquo;s [&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-2371","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: Dr. Scripto helps an Admin learn how to easily modify custom attributes in Active Directory. Microsoft Scripting Guy, Ed Wilson, here. If you missed it yesterday, see Sean&rsquo;s latest video: Just Script It! Also be sure to read yesterday&rsquo;s post before you start on today&rsquo;s: &lsquo;Twas the Night of Before Scripting: Part 1. Here&rsquo;s [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2371","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=2371"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2371\/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=2371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}