Get-aduser-filter *-properties *-searchbase "dc=uxin,dc=youxinpai,dc=com" |? {$_.lockedout-eq "true"} |unlock-adaccount
account Unlock Email notification
import-Module ActiveDirectory$users= Get-aduser-Filter*-properties *-searchbase"dc=uxin,dc=youxinpai,dc=com"| ? {$_. lockedout-eq "true"}#$unames = $users |select sAMAccountName$nls= ($users|measure). Count#$nlsIf($nls -GT20) { foreach($u inch $users) {[array]$uus+=$u. sAMAccountName +"' n"Get-aduser$u. sAMAccountName | unlock-Adaccount}#Defining mail servers $smtpServer="mail.yy.com" $smtpUser="[email protected]" $smtpPassword="Pass" $mail= new-Object System.Net.Mail.MailMessage#Define sender email address, recipient email address $MailAddress="[email protected]" $MailtoAddress="[email protected]" $mail. from = New-object System.Net.Mail.MailAddress ($MailAddress) $mail. To.add ($MailtoAddress) #Define message title, priority, and body $mail. Subject ="Locked User number is $NLS"; $mail. Priority =" High" $mail. Body ="Locked AD Users has unlocked.users is: ' N $uus" $SMTP= New-object System.net.mail.smtpclient-argumentlist$smtpServer $SMTP. Credentials = New-object system.net.networkcredential-argumentlist$smtpUser,$smtpPassword $SMTP. Send ($mail) }
AD Account Unlocked