#密码续期
#给最近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
}
}
}