Home
%3CLINGO-SUB%20id%3D%22lingo-sub-856296%22%20slang%3D%22en-US%22%3EPowerShell%20Basics%3A%20How%20To%20Unlock%20A%20User%20In%20Active%20Directory%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-856296%22%20slang%3D%22en-US%22%3E%3CP%3EEveryone%20makes%20mistakes.%20Sometimes%20end%20users%20forget%20their%20passwords%20and%20lock%20themselves%20out%20of%20their%20Active%20Directory%20access.%20Administrators%20can%20unlock%20these%20accounts%20via%20the%20Windows%20GUI%2C%20but%20what%20if%20there%20was%20a%20quicker%20way.%26nbsp%3B%20The%20PowerShell%20Active%20Directory%20module%20can%20save%20administrators%20time%20in%20governing%20end%20users%20and%20can%20also%20provide%20automation%20if%20required.%26nbsp%3B%20This%20example%20will%20highlight%20how%20to%20unlock%20an%20end%20user%20account%20in%20minimal%20steps%20via%20PowerShell%20and%20the%20Active%20Directory%20module.%26nbsp%3B%20Let's%20get%20started.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EOpen%20PowerShell%20in%20Administrative%20mode%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F131872i5A755AA2CF8E7946%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22How_To_Unlock_A_User_In_Active_Directory_via_PowerShell_001.png%22%20title%3D%22How_To_Unlock_A_User_In_Active_Directory_via_PowerShell_001.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EHow%20To%20Unlock%20A%20User%20In%20Active%20Directory%20With%20PowerShell%3C%2FSPAN%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20command%20to%20install%20the%20Active%20Directory%20module%3A%3CBR%20%2F%3E%26nbsp%3B%3CPRE%3EInstall-Module%20ActiveDirectory%3C%2FPRE%3E%0A%3CP%3E%3CBR%20%2F%3EOr%20confirm%20the%20module%20is%20loaded%20using%20the%20following%20command%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CPRE%3EGet-Module%20ActiveDirectory%3C%2FPRE%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3EWith%20the%20Active%20Directory%20PowerShell%20module%20now%20installed%2C%20run%20the%20following%20command%20to%20display%20and%20confirm%20that%20the%20user%20is%20locked%20out%3A%3CBR%20%2F%3E%26nbsp%3B%0A%3CPRE%3EGet-ADUser%20-Identity%20'ENTER%20USER%20NAME%20HERE'%20-Properties%20LockedOut%20%7C%20Select-Object%20Name%2CLockedout%3C%2FPRE%3E%0A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20command%20to%20unlock%20the%20user%20account%3A%3CBR%20%2F%3E%26nbsp%3B%0A%3CPRE%3EUnlock-ADAccount%20-Identity%20'ENTER%20USER%20NAME%20HERE'%20%3C%2FPRE%3E%0A%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20command%20again%20to%20confimr%20that%20the%20user's%20account%20has%20been%20unlocked%3A%3CBR%20%2F%3E%26nbsp%3B%0A%3CPRE%3EGet-ADUser%20-Identity%20'ENTER%20USER%20NAME%20HERE'%20-Properties%20LockedOut%20%7C%20Select-Object%20Name%2CLockedout%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-856296%22%20slang%3D%22en-US%22%3E%3CP%3EEveryone%20makes%20mistakes.%20Sometimes%20end%20users%20forget%20their%20passwords%20and%20lock%20themselves%20out%20of%20their%20Active%20Directory%20access.%20Administrators%20can%20unlock%20these%20accounts%20via%20the%20Windows%20GUI%2C%20but%20what%20if%20there%20was%20a%20quicker%20way.%26nbsp%3B%20The%20PowerShell%20Active%20Directory%20module%20can%20save%20administrators%20time%20in%20governing%20end%20users%20and%20can%20also%20provide%20automation%20if%20required.%26nbsp%3B%20This%20example%20will%20highlight%20how%20to%20unlock%20an%20end%20user%20account%20in%20minimal%20steps%20via%20PowerShell%20and%20the%20Active%20Directory%20module.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F59633i420FEE9A9109E151%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22PowerShell_Basics.jpg%22%20title%3D%22PowerShell_Basics.jpg%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EPowerShell%20Basics%3A%20How%20To%20Unlock%20A%20User%20In%20Active%20Directory%20With%20PowerShell%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-856296%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAnthony%20Bartolo%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867043%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20Basics%3A%20How%20To%20Unlock%20A%20User%20In%20Active%20Directory%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867043%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Anthony%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere's%20a%20few%20things%20in%20this%20post%20that'll%20probably%20cause%20a%20bit%20of%20confusion%20%2F%20errors%3A%3CBR%20%2F%3EThe%20first%20step%20implies%20that%20you'll%20need%20to%20start%20PowerShell%20in%20an%20elevated%20prompt%20every%20time%20you%20want%20to%20do%20this%2C%20when%20in%20fact%20you%20really%20only%20need%20it%20to%20call%20Install-Module%20when%20not%20using%20the%20CurrentUser%20scope.%3CBR%20%2F%3EAside%20from%20that%2C%20ActiveDirectory%20isn't%20actually%20available%20from%20any%20default%20repositories%2C%20and%20is%20part%20of%20the%20RSAT%20windows%20features%2C%20now%20you%20can%20activate%20those%20in%20any%20number%20of%20ways%20depending%20on%20where%20you're%20doing%20it%20from%2C%20the%20one%20most%20likely%20to%20be%20used%20is%20probably%20to%20import%20the%20ServerManager%20module%20and%20use%20its%26nbsp%3B%3C%2FP%3E%3CPRE%3EAdd-WindowsFeature%20RSAT-AD-Powershell%3C%2FPRE%3E%3CP%3ENow%20you%20say%20to%20use%20Get-Module%20to%20make%20sure%20its%20imported%2C%20and%20even%20though%20the%20AD%20module%20actually%20implicitly%20imports%20when%20you%20use%20a%20command%20from%20it%2C%20this%20is%20sensible%20enough.%20The%20problem%20however%2C%20is%20that%20we've%20not%20yet%20imported%20it%2C%20so%20this%20command%20will%20just%20return%20nothing%20as%20it%20defaults%20to%20look%20at%20imported%20modules%20(Speaking%20of%2C%20you%20don't%20ever%20mention%20Import-Module%20in%20the%20post).%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867065%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20Basics%3A%20How%20To%20Unlock%20A%20User%20In%20Active%20Directory%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867065%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Shoisk%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20sharing.%26nbsp%3B%20Not%20everyone's%20scenario%20is%20the%20same%20and%20my%20plan%20was%20to%20share%20the%20baseline%20in%20terms%20of%20the%20solution%20itself.%26nbsp%3B%20This%20provides%20the%20opportunity%20for%20others%2C%20like%20yourself%2C%20to%20build%20upon%20and%20make%20this%20post%20better.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-868521%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20Basics%3A%20How%20To%20Unlock%20A%20User%20In%20Active%20Directory%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-868521%22%20slang%3D%22en-US%22%3E%3CP%3ESearch-ADAccount%20-LockedOut%20will%20list%20Locked%20AD%20Accounts.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Everyone makes mistakes. Sometimes end users forget their passwords and lock themselves out of their Active Directory access. Administrators can unlock these accounts via the Windows GUI, but what if there was a quicker way.  The PowerShell Active Directory module can save administrators time in governing end users and can also provide automation if required.  This example will highlight how to unlock an end user account in minimal steps via PowerShell and the Active Directory module.  Let's get started.

 

    1. Open PowerShell in Administrative mode
       
      How_To_Unlock_A_User_In_Active_Directory_via_PowerShell_001.pngRun PowerShell
       
    2. Run the following command to install the Active Directory module:
       
      Install-Module ActiveDirectory


      Or confirm the module is loaded using the following command:

      Get-Module ActiveDirectory



    3. With the Active Directory PowerShell module now installed, run the following command to display and confirm that the user is locked out:
       
      Get-ADUser -Identity 'ENTER USER NAME HERE' -Properties LockedOut | Select-Object Name,Lockedout


    4. Run the following command to unlock the user account:
       
      Unlock-ADAccount -Identity 'ENTER USER NAME HERE' 
       

    5. Run the following command again to confimr that the user's account has been unlocked:
       
      Get-ADUser -Identity 'ENTER USER NAME HERE' -Properties LockedOut | Select-Object Name,Lockedout
3 Comments
Occasional Visitor

Hi Anthony,

 

There's a few things in this post that'll probably cause a bit of confusion / errors:
The first step implies that you'll need to start PowerShell in an elevated prompt every time you want to do this, when in fact you really only need it to call Install-Module when not using the CurrentUser scope.
Aside from that, ActiveDirectory isn't actually available from any default repositories, and is part of the RSAT windows features, now you can activate those in any number of ways depending on where you're doing it from, the one most likely to be used is probably to import the ServerManager module and use its 

Add-WindowsFeature RSAT-AD-Powershell

Now you say to use Get-Module to make sure its imported, and even though the AD module actually implicitly imports when you use a command from it, this is sensible enough. The problem however, is that we've not yet imported it, so this command will just return nothing as it defaults to look at imported modules (Speaking of, you don't ever mention Import-Module in the post). 

Microsoft

Hi Shoisk,

 

Thank you for sharing.  Not everyone's scenario is the same and my plan was to share the baseline in terms of the solution itself.  This provides the opportunity for others, like yourself, to build upon and make this post better. 

Regular Visitor

Search-ADAccount -LockedOut will list Locked AD Accounts.