Chinaunix首页 | 论坛 | 博客
  • 博客访问: 84690
  • 博文数量: 9
  • 博客积分: 1460
  • 博客等级: 上尉
  • 技术积分: 580
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-08 10:51
文章分类
文章存档

2008年(9)

我的朋友

分类: WINDOWS

2008-03-19 14:52:51

'#cas.vbs
'List user's information (display name, logon name, lock, member of)
'by display name (the same as CN) or logon name


Name = wscript.arguments.item(0)
If InStr(Name, " ") Then
    chkUsr (name)
Else
    eumName (Name)
End If

''''''''''Enumerate user cn'''''''''''''''''
Sub eumName(names)
on error resume next
strcontainer = "OU=Users"
exist=false
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objitem = GetObject("LDAP://" & strcontainer & "," & objRootDSE.get("defaultNamingContext"))
For Each obji In objitem
    upn = obji.get("userPrincipalName")
    If InStr(upn, "@") <> 0 Then
        upn = Left(upn, InStr(upn, "@") - 1)
    End If
    If upn = UCase(names) Then
        chkUsr (obji.get("name"))
        exist=true
        Exit For
    End If
Next
if not exist then
    wscript.echo "Error user name of assigned."
end if
End Sub

'''''''''''Output cn information''''''''''''
Sub chkUsr(names)
'''''''''''Connect to an object'''''''''''''
On Error Resume Next
strcontainer = "OU=Users"
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objitem = GetObject("LDAP://CN=" & names & "," & strcontainer & "," & objRootDSE.get("defaultNamingContext"))
'''''''''''Display information''''''''''''''
Select Case Err.Number
    Case -2147016656
        wscript.echo "Error user name of assigned."
    Case 9
        wscript.echo "Non user name assign"
    Case 0
        wscript.echo objitem.get("name")
        wscript.echo objitem.get("userPrincipalName")
        If objitem.isaccountlocked Then
            wscript.echo "Account Locked"
        Else
            wscript.echo "Account Unlocked"
        End If
        strmemberOf = objitem.GetEx("memberOf")
        wscript.echo "MemberOf:"
        For Each Item In strmemberOf
            Item = Left(Item, InStr(Item, ",") - 1)
            wscript.echo vbTab & Right(Item, Len(Item) - InStr(Item, "="))
        Next
End Select
End Sub
阅读(1146) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:VBScript查询域内帐户信息(效率版)

给主人留下些什么吧!~~