none
Creating a script for lockout statistics over a period of ~30 days RRS feed

  • Question

  • Greetings,

    I have created a simple piece of code to make an account lockout checker and unlock tool on powershell, im very new to it and just getting the hang of it, im trying to implement this into my work environment (IT ServiceDesk) and was hoping to try and get a script that can provide the statistics against lockouts over a period of say, 30 days. I have pasted my code below and if there is any advice that would be great.

     
    Import-Module ActiveDirectory
    cls
    write-host "------------------------------------------------------------------------------------" -ForeGroundColor Magenta
    write-host "|--Please note that this script is subject to change and is not the final version--|" -ForegroundColor Green 
    write-host "| Welcome to the pre-release of the AD Account unlocker and Lockout checker script |" -ForegroundColor Yellow
    write-host "| ------------------------------This is version 1.40------------------------------ |" -ForegroundColor Green
    write-host "| -------Please can any suggestions or errors be reported to Ben Cotterell!------- |" -ForegroundColor Yellow
    write-host "------------------------------------------------------------------------------------" -ForegroundColor Magenta
    
    DO {
    write-host "Please select one of the below scripts to run using the appropriate key assigned beforehand"
    write-host "[O] Lockout Checker Tool"
    write-host "[P] Account unlocker"
    $answer = Read-Host "Option"
    write-host " "
    IF ($answer -eq "o"){
        #LockoutChecker
        Search-ADAccount -LockedOut | Select-Object -Property SamAccountName,PasswordExpired,LastLogonDate
        }
    
    ELSEIF ($answer -eq "p"){
        #AccountUnlocker
        Search-ADAccount -LockedOut | Unlock-ADAccount -Confirm
        }
    }UNTIL($answer -eq "End")

       


    When running this it works fine other than the fact when it opens if I select the 'O' option, nothing happens and it just asks me to input another option, when I then input 'O' again it pastes out the information regarding lockouts twice. When I then press it 1 more time it gives me the data without any duplications but it removes the information bar at the top (SamAccountName,PasswordExpired,LastLogonDate).

    Any help is greatly appreciated, cheers


    Wednesday, August 14, 2019 8:23 AM

Answers

  • I have tested your script and it is showing the same behavior as you mentioned. As a work around you can use out-gridview.

    Search-ADAccount -LockedOut |

    Select-Object -Property SamAccountName,PasswordExpired,LastLogonDate |

    Out-GridView -Wait



    • Edited by asharma5 Wednesday, August 14, 2019 10:36 AM
    • Marked as answer by Ben Cotterell Wednesday, August 14, 2019 1:05 PM
    Wednesday, August 14, 2019 10:36 AM

All replies

  • Please post your script inside the Scriptblock. Currently your script is not readable.
    • Marked as answer by Ben Cotterell Wednesday, August 14, 2019 1:05 PM
    • Unmarked as answer by Ben Cotterell Wednesday, August 14, 2019 1:08 PM
    Wednesday, August 14, 2019 10:17 AM
  • I have tested your script and it is showing the same behavior as you mentioned. As a work around you can use out-gridview.

    Search-ADAccount -LockedOut |

    Select-Object -Property SamAccountName,PasswordExpired,LastLogonDate |

    Out-GridView -Wait



    • Edited by asharma5 Wednesday, August 14, 2019 10:36 AM
    • Marked as answer by Ben Cotterell Wednesday, August 14, 2019 1:05 PM
    Wednesday, August 14, 2019 10:36 AM
  • Thats worked a treat, thank you
    Wednesday, August 14, 2019 1:05 PM