'#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) |