批量给微软域用户进行密码续期

#密码续期
#给最近60天内登录的用户进行密码续期
#续期用户只包含密码已过期人员

$Date1 = (Get-Date).AddDays(-60)
$Date2= (Get-Date)
Get-ADUser  -SearchBase "OU=x,DC=x,DC=com" -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False  -and  LastLogonDate -gt $Date1} –Properties "DisplayName","SamAccountName","msDS-UserPasswordExpiryTimeComputed","LastLogonDate" |
Select-Object -Property "Displayname","SamAccountName",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} |
ForEach-Object{

if($_.ExpiryDate){
if($_.ExpiryDate -le $Date2){
Set-ADUser -Identity $_.SamAccountName -ChangePasswordAtLogon $true 
Set-ADUser -Identity $_.SamAccountName -ChangePasswordAtLogon $false
}
}
}
上一篇:1046 Shortest Distance (20point(s))


下一篇:Windows Server 2016-批量设置用户下次登陆须更改密码