首页 > 系统相关 >Powershell获取1年内未改密码的用户

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

时间:2023-01-16 15:02:38浏览次数:39  
标签:未改 PasswordLastSet ou DC 密码 user OU Powershell

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

1、定义OU搜索范围:OU=BYSSOFT_OBJECT,DC=byssoft,DC=com

2、定义输出结果文件

#建议保存编码为: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

3、执行成功

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

4、输出结果

Powershell获取1年内未改密码的用户_密码过期_02

标签:未改,PasswordLastSet,ou,DC,密码,user,OU,Powershell
From: https://blog.51cto.com/gaowenlong/6010437

相关文章