Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Purpose: Unlocks Active Directory accounts
- # Requirements: Network admin rights
- # Author: vocatus on reddit.com/r/usefulscripts
- # History: 1.0 Initial write
- # Usage: Pass account names to be unlocked as arguments, e.g. .\unlock_AD_account.ps1 john.smith fry leela
- #############
- # VARIABLES # -- Set these
- #############
- # Logging information. No trailing slashes (\) on directory names
- $LOGPATH=$env:systemdrive + "\Logs"
- $LOGFILE=$env:computername + "_unlock_AD_account.log"
- # Don't touch anything below this line
- $CUR_DATE=get-date -f "yyyy-MM-dd"
- #############
- # EXECUTION #
- #############
- # If no arguments were passed, spit out a message and die.
- if (! $args) {
- write-host
- Write-Host "Pass names of accounts to unlock, separated by spaces. e.g. .\unlock_AD_account.ps1 MyAccountName MySecondAccountName" -foregroundcolor white
- write-host
- Break
- }
- # Log that the script was triggered
- "$CUR_DATE "+ $(get-date -f "hh:mm:ss") + " Account lockout script triggered. Executing..." >> $LOGPATH\$LOGFILE
- # Do the unlock
- foreach ($i in $args) {
- unlock-adaccount $i
- write-host $i unlocked -foregroundcolor green
- "$CUR_DATE "+ $(get-date -f "hh:mm:ss") + " $i unlocked" >> $LOGPATH\$LOGFILE
- #if $LASTEXITCODE -ne "0" write-host $i failed to unlock -foregroundcolor red
- }
Add Comment
Please, Sign In to add comment