PowerShell LDAP信息查询


Import-Module ActiveDirectory #导入AD模块
while($true)
{
$ldap=Read-Host "please input your ldap"
$pass=Get-ADUser * -Properties * #获取用户*的账户所有属性
$last=$pass.passwordlastset #获取属性里上次密码更改属性值
$change=$last.AddDays(180)#增加3个月
$now=Get-Date
$change_days=($change-$now).days
$day=$now-$last
$days=$day.Days
$gin=$pass.EmployeeNumber

if($days -gt 170)
{
Write-Host "password need to be changed"

}
else{
Write-Host "pasword will be expired after $change_days days"
Write-Host "password status is good" #未判断是不是重置的情况,只判断了在密码有效期之内,请注意
Write-Host "GIN Number is" $gin #判断员工号
}
}
本文链接: https://www.pstips.net/powershell-ldap-query.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注