{"id":12731,"date":"2011-09-11T00:01:00","date_gmt":"2011-09-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/09\/11\/batchman-uses-powershell-to-identify-and-unlock-user-accounts\/"},"modified":"2011-09-11T00:01:00","modified_gmt":"2011-09-11T00:01:00","slug":"batchman-uses-powershell-to-identify-and-unlock-user-accounts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/batchman-uses-powershell-to-identify-and-unlock-user-accounts\/","title":{"rendered":"BATCHman Uses PowerShell to Identify and Unlock User Accounts"},"content":{"rendered":"<p><strong>Summary<\/strong>: BATCHman shows how to use Windows PowerShell to locate and unlock user accounts in Active Directory.\n&nbsp;\nMicrosoft Scripting Guy Ed Wilson here. In the continuing saga of the world&rsquo;s first Windows PowerShell superhero, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/batchman\/\">BATCHman<\/a>, and his faithful sidekick, Cmdlet, I once again present Windows PowerShell MVP and <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/honorary-scripting-guy-award-recipients-announced\/\">Honorary Scripting Guy<\/a> <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/guest+blogger\/sean+kearney\/\">Sean Kearney<\/a>. &nbsp;\n<a href=\"http:\/\/i.technet.microsoft.com\/bb410849.Batchman_Icon_05_bluebatchman_082511(en-us,MSDN.10).png\"><img decoding=\"async\" style=\"max-width: 550px;border: 0px\" title=\"BATCHman and Cmdlet logo\" alt=\"BATCHman and Cmdlet logo\" src=\"http:\/\/i.technet.microsoft.com\/bb410849.Batchman_Icon_05_bluebatchman_082511(en-us,MSDN.10).png\"><\/a>\nWhenever trouble happens in systems and people will call,\nAnd darkness rolls out causing your fall,\nCreatures of bits roam in the night,\nShine to the sky, the bright bluish Light,\nAnd call to&hellip;BATCHman !\n&hellip;and, oh yes, his sidekick Boy Blunder Cmdlet, too.\n&nbsp;\nShock! Terror! The Redmond Police office has been rendered useless! A dark shadow has crossed over the LAN!\n&ldquo;Our accounts! Every account in Active Directory locked out!&rdquo; the police chief stared blankly at the computer screen. He then glared darkly across the hallway at the culprit who is dressed in all black, hissing back at the police chief.\nIt was the dreaded Script Kitty, Madame CatFile&rsquo;s only daughter. For years, there was a chance of her not assuming her mother&rsquo;s role of foul villainry, and then the worst happened: she saw the cool clothes evil villains wore, and that was that. She was another victim of fashion.\nTonight, she had somehow slipped into the office in the guise of one of the cleaning staff and plugged her laptop into an unwatched LAN jack. She ran her &ldquo;AttackCityHall.vbs&rdquo; script in the hopes of unlocking at least one account. Fortunately for the city of Redmond and unfortunately for her, neither time nor password complexity rules was on her side.\nUnfortunately, the city had for security reasons designed its Active Directory to not automatically unlock. Thus, the poor police chief found himself in a predicament.\n&ldquo;Hiiiiissssss,&rdquo; Script Kitty hissed again at the chief.\nHow dare he walk in on her while she was attempting to hack all of the accounts in the city of Redmond? She would have gotten away, too, if it weren&rsquo;t for that oh-so-cute little mouse. She just <i>had<\/i> to pounce on it! After all, it was a pink Arc mouse. &ldquo;So rare! Purrrrr,&rdquo; her mind raced and then she was quickly caught and locked up.\nThere was only one account that Script Kitty missed. She, in her haste, somehow overlooked an administrator account.\nThe police chief looked over at the blue box on the wall with a small hammer marked, &ldquo;In case of network emergency, break glass and press button.&rdquo;\nThe glass shattered, the police chief did the one thing he never thought he&rsquo;d need to do: he summoned the BATCHman Klaxons.\nHe pressed the <strong>Get-Help<\/strong> button, and moments later, 1,000 loudspeakers inside his office began pumping out a 1,000-decibel warning siren along with a blinding light.\nCovering his ears and eyes, he stumbled across the room looking at the deputy. Taking a hammer to the <strong>Get-Help<\/strong> button and many sparks later, the sound and light disappeared.\nStaring at his deputy, he cursed, &ldquo;I told you, have them mount the BATCHman warning system <i>outside<\/i> the office, not inside!&rdquo; He quickly grabbed his cell phone and dialed BATCHman&rsquo;s private line.\n<b>***Moments later with a THUD and WHUMP***<\/b>\n&ldquo;Never fear, BATCHman is here!&rdquo; announced BATCHman.\nThe police chief looked up still recovering from the massive assault of sound and light. &ldquo;Yes! Thank goodness you&rsquo;re here! We are in dire need of your help!&rdquo; he shouted above the imagined din.\nBATCHman looked. &ldquo;No need to yell, good citizen. We can h&hellip;&rdquo;\nThe police chief gestured to all the loudspeakers in the office as well as the broken BATCHman blue box.\n&ldquo;Ahhhh, not again. Must remember, outside not inside.&rdquo;\nQuickly the Police chief guided him to the workstation &ldquo;We&rsquo;re locked out of Active Directory! Only one good account! Need to get in! GUI slow! Ears hurt, too!&rdquo;\nBATCHman thought for a moment. With Windows PowerShell, they could solve this easily. Nevertheless, they&rsquo;d have to identify the locked-out accounts to make this quick.\nQuickly, he entered the Windows PowerShell console and loaded up the <b>ActiveDirectory<\/b> module.<\/p>\n<p style=\"padding-left: 30px\">IMPORT-MODULE ActiveDirectory<i><\/i>\nCmdlet looked over. &ldquo;BATCHman, can we just pull up a user and have it show us whether they are locked out?&rdquo;\nEnjoying his sidekick&rsquo;s enthusiasm BATCHman noted, &ldquo;Yes, it is possible using the <b>Properties<\/b> parameter, but the <b>ActiveDirectory<\/b> module has a far more powerful feature called <b>SEARCH-ADACCOUNT<\/b>. To find all users locked out in Active Directory, we type this.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">SEARCH-ADACCOUNT &ndash;lockedout<i><\/i>\n&ldquo;But, Cmdlet, if we need to make this go faster and unlock only the computers in a particular organizational unit or OU, we can specify parameters such as <b>&ndash;searchbase<\/b>.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">SEARCH-ADACCOUNT &ndash;searchbase &lsquo;OU=Division31,OU=Locations,DC=Police,DC=Redmond,DC=Local&rsquo; &ndash;lockedout<i><\/i>\nNow, we can just quickly <b>UNLOCK<\/b> all the accounts by piping the results into <b>UNLOCK-ADACCOUNT<\/b>.<\/p>\n<p style=\"padding-left: 30px\">SEARCH-ADACCOUNT &ndash;searchbase &lsquo;OU=Division31,OU=Locations,DC=Police,DC=Redmond,DC=Local&rsquo; &ndash;lockedout | UNLOCK-ADACCOUNT<i><\/i>\nCmdlet blinked. One single line? &ldquo;Holy Simple Simon, BATCHman! Windows PowerShell really <i>is<\/i> powerful!&rdquo;\n&ldquo;Yes, it is. Now, quickly have the police chief verify that his staff and he can get in.&rdquo;\nThe police chief logged in and verified all was well. &ldquo;Thank you, BATCHman! You have saved the day! You&rsquo;re our hero!&rdquo;\nBATCHman covered his ears from the shouting. &ldquo;You&rsquo;re quite welcome good citizen.&rdquo;\nForgotten during all of this, Script Kitty looked up at BATCHman and purred, &ldquo;Your outfit is purrrfectly delightful.&rdquo;\nBATCHman looked over. &ldquo;Yes, maybe someday you&rsquo;ll learn about the power of good and of Windows PowerShell. Crime not only doesn&rsquo;t pay, it has a far worse budget for cool costumes.&rdquo;\n&nbsp;\nI want to thank Sean for another exciting episode of BATCHman. Join us tomorrow when The Scripting Wife learns about creating a profile for the Windows PowerShell console.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto: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.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b>\n&nbsp;\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: BATCHman shows how to use Windows PowerShell to locate and unlock user accounts in Active Directory. &nbsp; Microsoft Scripting Guy Ed Wilson here. In the continuing saga of the world&rsquo;s first Windows PowerShell superhero, BATCHman, and his faithful sidekick, Cmdlet, I once again present Windows PowerShell MVP and Honorary Scripting Guy Sean Kearney. &nbsp; [&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":[7,284,56,3,154,20,45],"class_list":["post-12731","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-batchman","tag-guest-blogger","tag-scripting-guy","tag-sean-kearney","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: BATCHman shows how to use Windows PowerShell to locate and unlock user accounts in Active Directory. &nbsp; Microsoft Scripting Guy Ed Wilson here. In the continuing saga of the world&rsquo;s first Windows PowerShell superhero, BATCHman, and his faithful sidekick, Cmdlet, I once again present Windows PowerShell MVP and Honorary Scripting Guy Sean Kearney. &nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/12731","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=12731"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/12731\/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=12731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=12731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=12731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}