$xiaoxie =@('a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z')
$daxie =@('A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z')
$shuzi =@('2','3','4','5','6','7','8','9')
$fuhao =@('&','$','-','=')
$xxxx =@('xiaoxie','daxie','shuzi','fuhao')
$hashtable = New-Object System.Collections.Hashtable
$hashtable= @{
'xiaoxie' = $xiaoxie
'daxie' = $daxie
'shuzi' = $shuzi
'fuhao' = $fuhao
}
$mimacount =10
function suijimima {
$countsuiji=$xxxx|Get-Random
$a =[string]($hashtable.$countsuiji|Get-Random )
$a
}
Import-Module ActiveDirectory
$SMTPServer = "XXXXXXXXXXXXX"
$SMTPPort = "587"
$SMTPAccount = "XXXXXXXXXXXXX"
$SecureFile = "D:pwd.txt"
$SecurePwd = Get-Content $SecureFile | ConvertTo-SecureString
$SMTPCred = New-Object System.Management.Automation.PSCredential($SMTPAccount,$SecurePwd)
$EmailLast = "XXXXXXXX"
$AllUser = Get-ADUser -searchbase "OU=XX,DC=XXX,DC=com" -Filter 'PasswordNeverExpires -eq "false" -and enabled -eq "true"' | % {$_.SamAccountName}
$Count = 0
foreach ($User in $AllUser){
$PwdLastset = Get-ADUser $User -Properties passwordlastset | % {$_.passwordlastset}
$PwdLastday = ($PwdLastset).AddDays(90)
$Now = Get-Date
$ExpireDays = ($PwdLastday - $Now).Days
if($ExpireDays -gt "20"){
$Count = $Count + 1
$bx=""
for ($i=1;$i -lt $mimacount+1;$i++)
{
$bx2=suijimima
$bx += $bx2
}
$User | Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $bx -Force)
$EmailAddress = "$User$EmailLast"
$EmailSubject = "过期账号密码已修改"
$Emailbody =
@"
您的域账号 $User 密码已经修改为 $bx 。
"@
Send-MailMessage -UseSsl -Credential $SMTPCred -From $SMTPAccount -Subject $EmailSubject -To $EmailAddress -Body $Emailbody -Encoding ([System.Text.Encoding]::UTF8) -Port $SMTPPort -SmtpServer $SMTPServer
Send-MailMessage -UseSsl -Credential $SMTPCred -From $SMTPAccount -Subject $EmailSubject -To "821271702@qq.com" -Body $Emailbody -Encoding ([System.Text.Encoding]::UTF8) -Port $SMTPPort -SmtpServer $SMTPServer
}
}
$EmailSubject1 = "修改密码数量 "
$Emailbody1 =
@"
XXXXX 域控 一共发出 $Count 份邮件
"@
Send-MailMessage -UseSsl -Credential $SMTPCred -From $SMTPAccount -Subject $EmailSubject1 -To "821271702@qq.com" -Body $Emailbody1 -Encoding ([System.Text.Encoding]::UTF8) -Port $SMTPPort -SmtpServer $SMTPServer
自动修改过期账号密码
最新推荐文章于 2024-07-25 22:32:28 发布