Manually checking users from a trusted domain
How can I check a user in a trusted domain exis开发者_StackOverflowts and after that how can I check that the same user is not enabled?
Since this was posted on SO, I will assume you want a programming solution.
Since you didn't specify a language, I will also assume that Powershell is acceptable.
Test if user exists in domain:
$netbiosdomainname = "DOMAIN"
$username = "johndoe"
try {
[adsi]::Exists("WinNT://$netbiosdomainname/$username,user")
}
catch {
... user does not exist ...
}
See this article for why this needs try/catch.
Test if user enabled:
$user = [adsi]"WinNT://$netbiosdomainname/$username,user"
if ($user.AccountDisabled) {
... account is disabled ...
}
精彩评论