{"id":16141,"date":"2010-12-22T00:01:00","date_gmt":"2010-12-22T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/12\/22\/a-windows-powershell-carol-ebenezer-script-manages-ad-users\/"},"modified":"2010-12-22T00:01:00","modified_gmt":"2010-12-22T00:01:00","slug":"a-windows-powershell-carol-ebenezer-script-manages-ad-users","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/a-windows-powershell-carol-ebenezer-script-manages-ad-users\/","title":{"rendered":"A Windows PowerShell Carol: Ebenezer Script Manages AD Users"},"content":{"rendered":"<p><span style=\"font-size:10.0pt\"><\/span>\n<span style=\"font-size:10.0pt\"><\/span>\n<b><span style=\"font-size:10.0pt\">Summary:<\/span><\/b><span style=\"font-size:10.0pt\"> A Windows PowerShell Carol in which Ebenezer Script learns how to use PowerShell to manage users in Active Directory.<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\"><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>Hey, Scripting Guy! Can you tell me if Ebenezer Script will learn how to work with Active Directory users from within Windows PowerShell?<\/span>\n<span style=\"font-size:10.0pt\">&#8212; JC<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\"><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>Hello JC, Microsoft Scripting Guy Ed Wilson here. It is almost the end of the year and we have decided to devote some posts to the holiday season. We even have guest bloggers from around the world to share some holiday spirit. This week we have Sean Kearney. You can learn more about Sean in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/12\/19\/weekend-scripter-holiday-powershell-carol-part-one.aspx\">Monday&rsquo;s blog introduction<\/a>. Be sure to check out <a href=\"https:\/\/www.youtube.com\/watch?v=v04BXhlPxyY\">Sean&rsquo;s theme song for this week&rsquo;s PowerShell Carol posts<\/a>.<\/span>\n&nbsp;\n<span style=\"font-size:10.0pt\">Ebenezer lay back in the bed. He really had to lay off snacking on whatever he found in the back of his desk drawer. The nasty habit was producing strange visions, and funny breath, too.<\/span>\n<span style=\"font-size:10.0pt\">He lay on his bed, a mattress comprised of billions of chits from Dot Matrix printers. The framework composed of VT52 Monitor terminals. A pillow comprised of the softest bubble wrap packaging that was delicately laced with peanut packaging and duct tape to hold it all together. Nerdy but cool. It was wonderfully uncomfortable.<\/span>\n<span style=\"font-size:10.0pt\">He dozed off almost immediately, sleeping, perchance to dream&hellip;<\/span>\n<span style=\"font-size:10.0pt\">It felt as though he was asleep for a decade when suddenly a sound echoed through the house, much like a giant 50-foot tall floppy drive opening up.<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer woke with a bolt. As fate would have it, he found himself face to face with a giant rendition of an 8&rdquo; floppy drive complete with cable, blinking red light and Shugart interface card.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-size:10.0pt\">&ldquo;$EBENEZER!&rdquo; It whirred, &ldquo;I AM {$PERL} The Spirit of Scripting Past! Awake now and follow my processes!&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer whipped up a small magnet lying at the side of his bed, pulling the covers over his head. &ldquo;Go away! You&rsquo;re just a bad idea some writer coughed up.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Angered and whirring faster the spirit buzzed back, &ldquo;$FOLLOW $ME!&rdquo; and spinning up pulled Ebenezer, sheets and all, within his mighty 5 volt motor. Ebenezer went quickly, spinning away inside the Giant Floppy, frantically reaching for the eject lever.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-size:10.0pt\">&ldquo;Tonight,&rdquo; the spirit buzzed, &ldquo;we will show you visions of what you were before you changed.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">The spirit pulled a backup disk and inserted it within his mouth; his single red light aglow as they entered the past.<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer suddenly found himself staring at a very young IT person, with hair. Eyes alit with energy and passion. He was actually smiling.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-size:10.0pt\">&ldquo;This was you once. You used to smile.&rdquo;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-size:10.0pt\">&ldquo;I used to have hair, too, and once I even had a case of the hives. You don&rsquo;t see me reminiscing about THAT,&rdquo; snapped Ebenezer.<\/span>\n<span style=\"font-size:10.0pt\">The Spirit of Scripting Past smacked him in the back of the head with his giant ribbon cable. &ldquo;LOOK!&rdquo; it spoke.<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer looked. He saw Jacob Clippy smiling. A table littered with scraps of paper, madly running about. The young fellow was pulling a list of users who had not logged in recently. He did it not with disdain, but with a wild and smiling look in his eyes; with love and joy.<\/span>\n<span style=\"font-size:10.0pt\">The Spirit pointed to a small VBScript a younger Ebenezer was writing. &ldquo;Do you remember this?&rdquo;<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size:10.0pt\">C<span style=\"font-family: courier new,courier\">onst DisableUser = 2<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">set User=GetObject(&#8220;LDAP:\/\/CN=ken.myer,OU=Users,OU=Office,DC=Contoso,DC=local&#8221;)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">AccountUAC=User.Get(&#8220;userAccountControl&#8221;)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">User.Put &#8220;userAccountControl&#8221;, AccountUAC OR DisableUser<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">User.SetInfo<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Oh my! That was the first time I wrote a script in VBScript to disable a User Account in our Active Directory! It&rsquo;s been so long I had forgotten. Yes. YES! I remember that day. It was like unlocking a puzzle. I suddenly felt like I had control!&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;You remember those days Ebenezer?&rdquo; the spirit invoked, &ldquo;There was a light in your eyes once that showed pure passion.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Yes,&rdquo; muttered Ebenezer, &ldquo;I do remember. It was all so wonderful, until THAT day; the day the work requests overloaded me. There was no support from the outside. Scripting alone did not seem to help.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">The users; Ebenezer shuddered from the cold and the thought of an overloaded pile of IT Service Requests. He had learned to despise the Users.<\/span>\n<span style=\"font-size:10.0pt\">The Spirit of Scripting Past looked at Ebenezer. <\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Would it interest you to know that VBScript is not so different from Windows PowerShell? Take a look at your original VBScript script as it might appear in Windows PowerShell.&rdquo;<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size:10.0pt\">$<span style=\"font-family: courier new,courier\">DisableUser = 2<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$User=[ADSI]::&#8221;LDAP:\/\/192.168.1.5\/CN=ken.myer,OU=Users,OU=Office,DC=Contoso,DC=local&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$AccountUAC=($User.userAccountControl)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$User.Put (&#8220;userAccountControl&#8221;, $AccountUAC.AccountUUAC &ndash;bor DisableUser)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$User.SetInfo()<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/span>\n<span style=\"font-size:10.0pt\">Ebenezer was stunned. With the exception of a minor change, it was almost identical.<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Fine Spirit, they&rsquo;re almost the same. So why do people even CARE about Windows PowerShell? What&rsquo;s the big deal?&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">&ldquo;Because,&rdquo; the Spirit paused dramatically, &ldquo;that very script can also be done in ONE LINE in Windows Server 2008 R2 or with some free tools from Quest.&rdquo;<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer blinked. &ldquo;One line of code? Bah! Codebug! Nothing could do that in one line!&rdquo; He spat with great vengeance to the wind.<\/span>\n<span style=\"font-size:10.0pt\">The Spirit of Scripting past spun up his floppy with great majesty as two lines of Windows PowerShell appeared before Ebenezer.<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size:10.0pt\">U<span style=\"font-family: courier new,courier\">NLOCK-ADACCOUNT &ndash;identity &lsquo;ken.myer&rsquo;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"margin-left: 0in;background: transparent\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">UNLOCK-QADUSER ken.myer<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\"><\/span><\/span>\n<span style=\"font-size:10.0pt\"><\/span>\n<span style=\"font-size:10.0pt\">&ldquo;These are the lines of code used with Windows Server 2008 R2 and Quest Active Roles respectively,&rdquo; his voice echoed majestically, booming deeply into Ebenezer&rsquo;s head.<\/span>\n<span style=\"font-size:10.0pt\">Ebenezer&rsquo;s head began to spin. One line. One line of code. If only he had this kind of power when he was a young Scripter perhaps, the world would have been easier to manage. Perhaps he would have remained happy.<\/span>\n<span style=\"font-size:10.0pt\">Perhaps he would not have sent all those users to Winnipeg.<\/span>\n<span style=\"font-size:10.0pt\">VBscripts easily translating into Windows PowerShell and using one single line of code to disable a user was too much for poor Ebenezer Script as he fell over in a dead faint.<\/span>\n<span style=\"font-size:10.0pt\">Did the Spirit of Scripting Past get his message across? Will Ebenezer realize the joy he once held? Will the writer explain to us in great detail later just WHY the Spirit of Perl did not suggest Perl as a solution? Just how did Ebenezer ship a division of users to Winnipeg anyway? What is wrong with Winnipeg? I happen to like Winnipeg! Tune in tomorrow, same scripting time; same scripting channel. <\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span>\n<span style=\"font-size:10.0pt\">JC, that is all there is to using Windows PowerShell to work with Active Directory. Holiday guest blogger week will continue tomorrow when Sean will continue A Windows PowerShell Carol. <\/span>\n<span style=\"font-size:10.0pt\">I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> or post them on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/span>\n<span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><b><span style=\"font-size:10.0pt\">Ed Wilson, Microsoft Scripting Guy<\/span><\/b><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: A Windows PowerShell Carol in which Ebenezer Script learns how to use PowerShell to manage users in Active Directory. &nbsp; Hey, Scripting Guy! Can you tell me if Ebenezer Script will learn how to work with Active Directory users from within Windows PowerShell? &#8212; JC &nbsp; Hello JC, Microsoft Scripting Guy Ed Wilson here. [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,56,3,154,20,45],"class_list":["post-16141","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-guest-blogger","tag-scripting-guy","tag-sean-kearney","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: A Windows PowerShell Carol in which Ebenezer Script learns how to use PowerShell to manage users in Active Directory. &nbsp; Hey, Scripting Guy! Can you tell me if Ebenezer Script will learn how to work with Active Directory users from within Windows PowerShell? &#8212; JC &nbsp; Hello JC, Microsoft Scripting Guy Ed Wilson here. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16141","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=16141"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16141\/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=16141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}