Active directory 无法确定使用Powershell的脚本中的密码期限

Active directory 无法确定使用Powershell的脚本中的密码期限,active-directory,powershell-4.0,Active Directory,Powershell 4.0,早上好 我在尝试确定广告用户密码的年龄时遇到问题 运行以下脚本部分时: #检查细粒度密码 $PasswordPol=(获取ADUserResultantPasswordPolicy$user) if(($PasswordPol)-ne$null) { $maxPasswordAge=($PasswordPol).maxPasswordAge } $expireson=$passwordsetdate.AddDays($maxPasswordAge) $today=(获取日期) #获取密码过期的

早上好

我在尝试确定广告用户密码的年龄时遇到问题

运行以下脚本部分时:

#检查细粒度密码
$PasswordPol=(获取ADUserResultantPasswordPolicy$user)
if(($PasswordPol)-ne$null)
{
$maxPasswordAge=($PasswordPol).maxPasswordAge
}
$expireson=$passwordsetdate.AddDays($maxPasswordAge)
$today=(获取日期)
#获取密码过期的天数计数,并将其存储在$daystoexpire变量中
$daystoexpire=(新时间跨度-开始$today-结束$Expireson)。天
}
}
其他的
{
$daystoexpire=“不适用”
}
如果($User.Enabled-eq$True)和($AttVar.LastLogon-lt((Get Date.AddDays(-$Days))-和($User.LastLogon-ne$NULL))
{
$obj=[PSCustomObject]@{
“Name”=$User.Name
“UserPrincipalName”=$User.UserPrincipalName
“已启用”=$AttVar.Enabled
“受保护不被删除”=$User.protectedfromcidentialdelection
“上次登录”=$AttVar.lastlogon
“密码永不过期”=$AttVar.PasswordNeverExpires
“密码过期天数”=$daystoexpire
}
$userphaventloggedonrecentlytable.Add($obj)

}
您需要从时间跨度中提取天数,这应该可以做到

$passwordsetdate.AddDays(([timespan]$maxPasswordAge).totaldays)

伟大的请考虑接受它作为未来读者利益的答案