码迷,mamicode.com
首页 > 其他好文 > 详细

AD账号解锁

时间:2016-06-12 15:10:58      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

Get-ADUser -Filter * -Properties *  -SearchBase "dc=uxin,dc=youxinpai,dc=com"| ? {$_.lockedout -eq "true"} |unlock-adaccount

账号解锁发邮件通知

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
#$nls
If ($nls -gt 20)
    {
    foreach ($u in $users)
    {
    [array]$uus +=$u.samaccountname + "`n"
    
    Get-ADUser $u.samaccountname |Unlock-ADAccount
    }

    #定义邮件服务器
    $smtpServer = "mail.yy.com"
    $smtpUser = "sysuser@yy.com"
    $smtpPassword = "pass"
    $mail = New-Object System.Net.Mail.MailMessage

    #定义发件人邮箱地址、收件人邮箱地址
    $MailAddress="sysuser@yy.com"
    $MailtoAddress="ITsupport@yy.com"
    $mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
    $mail.To.Add($MailtoAddress)

    #定义邮件标题、优先级和正文
    $mail.Subject = "Locked User Number is $nls";
    $mail.Priority  = "High"
    $mail.Body = "Locked AD Users have 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账号解锁

标签:

原文地址:http://www.cnblogs.com/dreamer-fish/p/5577464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!