开发者

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 ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜