Powershell获取1年内未改密码的用户

余寿

关注

阅读 79

2023-01-16

Powershell获取1年内未改密码的用户


#建议保存编码为:bom头 + utf8
$ou = 'OU=BYS_Users,OU=BYS_Object,DC=byssoft,DC=com'

$ = 'd:\expireduser.txt'

$1 = (Get-Date).addyears(0)

$users = Get-ADUser -SearchBase $ou -filter { PasswordLastSet -lt $1 } -Properties samaccountname,msDS-UserPasswordExpiryTimeComputed,PasswordNeverExpires,PasswordLastSet

$ = @()

foreach ($user in $users)

{

$a = [PSCustomObject]@{

samaccountname = $user.samaccountname

ou = $user.DistinguishedName

= $user.PasswordLastSet

= [datetime]::FromFileTime($user.'msDS-UserPasswordExpiryTimeComputed')

#密码永不过期 = $user.PasswordNeverExpires

}

$ += $a

}

#$结果 | Sort-Object -Unique | Export-Csv -LiteralPath $输出文件 -Encoding unicode -NoTypeInformation

$ | Export-Csv -LiteralPath $ -Encoding unicode -NoTypeInformation


精彩评论(0)

0 0 举报