SHOW:
|
|
- or go back to the newest paste.
| 1 | - | # Purpose: Unlocks Active Directory accounts |
| 1 | + | # Purpose: Unlocks Active Directory accounts |
| 2 | - | # Requirements: Network admin rights |
| 2 | + | # Requirements: Network admin rights |
| 3 | - | # Author: vocatus on reddit.com/r/usefulscripts |
| 3 | + | # Author: vocatus on reddit.com/r/sysadmin and /r/usefulscripts |
| 4 | - | # History: 1.0 Initial write |
| 4 | + | # History: 1.1 + Added Prep section with standard variables to be consistent with other scripts |
| 5 | - | # Usage: Pass account names to be unlocked as arguments, e.g. .\unlock_AD_account.ps1 john.smith fry leela |
| 5 | + | # 1.0 Initial write |
| 6 | # Usage: Pass account names to be unlocked as arguments, e.g. .\unlock_AD_account.ps1 MyAccountName MySecondAccountName | |
| 7 | ||
| 8 | ||
| 9 | - | # VARIABLES # -- Set these |
| 9 | + | ######## |
| 10 | # Prep # | |
| 11 | ######## | |
| 12 | $VERSION="1.1" | |
| 13 | - | $LOGFILE=$env:computername + "_unlock_AD_account.log" |
| 13 | + | $UPDATED=2014-01-16 |
| 14 | $CUR_DATE=get-date -f "yyyy-MM-dd" | |
| 15 | - | # Don't touch anything below this line |
| 15 | + | |
| 16 | ############# | |
| 17 | # VARIABLES # -- Set these to your desired values | |
| 18 | ############# | |
| 19 | # Logging information. No trailing slashes (\) on directory names | |
| 20 | $LOGPATH=$env:systemdrive + "\Logs" | |
| 21 | $LOGFILE=$env:computername + "_AD_unlock_account.log" | |
| 22 | ||
| 23 | ||
| 24 | ############# | |
| 25 | # EXECUTION # | |
| 26 | ############# | |
| 27 | # If no arguments were passed, spit out a message and die. | |
| 28 | # AKA if "$args" is false / aka not true, then do this stuff | |
| 29 | if (! $args) {
| |
| 30 | write-host | |
| 31 | Write-Host "Pass names of accounts to unlock, separated by spaces. e.g. .\unlock_AD_account.ps1 MyAccountName MySecondAccountName" -foregroundcolor white | |
| 32 | write-host | |
| 33 | Break | |
| 34 | } | |
| 35 | ||
| 36 | # Log that the script was triggered | |
| 37 | "$CUR_DATE "+ $(get-date -f "hh:mm:ss") + " Account lockout script triggered. Executing..." >> $LOGPATH\$LOGFILE | |
| 38 | ||
| 39 | # Do the unlock | |
| 40 | foreach ($i in $args) {
| |
| 41 | unlock-adaccount $i | |
| 42 | write-host $i unlocked -foregroundcolor green | |
| 43 | "$CUR_DATE "+ $(get-date -f "hh:mm:ss") + " $i unlocked" >> $LOGPATH\$LOGFILE | |
| 44 | #if $LASTEXITCODE -ne "0" write-host $i failed to unlock -foregroundcolor red | |
| 45 | } |