1
我运行了两种不同的方式来检查用户是否可以更改密码。首先,我使用CMDLET进行查询,并且我得到了其中12个无法更改密码。然后我使用了matching rule bit and
的LDAP搜索,它什么也没有返回。这是什么原因?用户帐户控制和属性
1. Get-ADUser -Filter * -Properties CannotChangePassword| where {$_.CannotChangePassword} | sort-object {$_.samAccountName} | Select samAccountName
总用户不能改变密码是:12
2.
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$ADSearch = New-Object System.DirectoryServices.DirectorySearcher
$ADSearch.SearchRoot ="LDAP://$domain"
$ADSearch.SearchScope = "subtree"
$ADSearch.PageSize = 100
$ADSearch.Filter = "(&(objectCategory=person)(objectClass=user))"
$properies [email protected](
"sAMAccountName",
"userAccountControl"
)
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)| out-null
#the name of property of the object, search will load the name in an array #properties
}
$userObjects = $ADSearch.FindAll()
forEach ($user In $userObjects)
{
$accountDis= $user.Properties.Item("userAccountControl")[0]
$global:sam = $user.Properties.Item("sAMAccountName")[0]
if($accountDis -band 64){
$passChange ="Not allowed"
"""$accountDis","$passChange"
}
}
总用户不能改变密码是:0
所以你的意思是'ADS_UF_PASSWD_CANT_CHANGE'不能在这种情况下操纵?如果你能解释我为什么得到2个不同的结果,那将是很好的。并且'userAccountControl'也被复制。 – Ender