?

Log in

No account? Create an account

Previous Entry | Next Entry

Get_User_Info.vbs


'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: Get_User_Info.vbs
'
' AUTHOR: Carl R. Knecht
' DATE : 09/15/2005
'
' COMMENT: Given user name, provides full name and basic user account info.
'
' Send bug information and feature requests to Knecht, Carl R.
'
'==========================================================================
Cscript()
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
'AD setup
Set objRootDSE = GetObject("LDAP://RootDSE")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection

If WScript.Arguments.Count = 0 Then
WScript.StdOut.Write "Provide username ---> "
strUserName = Wscript.StdIn.ReadLine
Else
strUserName = WScript.Arguments(0)
End If

objCommand.CommandText = _
"<ldap://">;" & _
"(&(objectCategory=User)(samAccountName=" & strUserName & "));" & _
"distinguishedName,cn,title,department,telephoneNumber;subtree"
Set objRecordSet = objCommand.Execute

If objRecordSet.RecordCount => 1 Then
WScript.Echo "Client Name: " & objRecordset.Fields("cn")
WScript.Echo "Department: " & objRecordset.Fields("department")
WScript.Echo "Job Title: " & objRecordset.Fields("title")
WScript.Echo "Telephone: " & objRecordset.Fields("telephoneNumber")
WScript.Echo "Account Status: " & GetAccountStatus(objRecordset.Fields("distinguishedName"))
WScript.Echo "Password Expires: " & GetUserNonExpiring(objRecordset.Fields("distinguishedName"))
WScript.Echo "Password Age: " & DateDiff("d",GetObject("LDAP://" & objRecordset.Fields("distinguishedName")).PasswordLastChanged,Date)
WScript.Echo ""
WScript.Echo "LDAP Distinguished Name:"
WScript.Echo objRecordset.Fields("distinguishedName")
objRecordset.MoveNext
Else
WScript.Echo "User " & UCase(strUserName) & " not found in Active Directory."
End If
WScript.Quit

'*********************************************************
Sub Cscript()
Dim strCommand, intArgument
If Lcase(Right(Wscript.FullName, 12)) <> "\cscript.exe" Then
strCommand = "cscript.exe """ & Wscript.ScriptFullName & """"
Wscript.CreateObject("Wscript.Shell").Run strCommand
WScript.Quit
End If
End Sub

'*********************************************************
Function GetUserNonExpiring(strDistinguishedName)
On Error Resume Next
Set objUser = GetObject("LDAP:// " & strDistinguishedName)
intUAC = objUser.Get("userAccountControl")
If intUAC And ADS_UF_DONT_EXPIRE_PASSWD Then
GetUserNonExpiring = "No"
Else
GetUserNonExpiring = "Yes"
End If
End Function

'*********************************************************
Function GetAccountStatus(strDistinguishedName)
Set objUser = GetObject("LDAP://" & strDistinguishedName)
If objUser.AccountDisabled = 0 Then
GetAccountStatus = "Active"
Else
GetAccountStatus = "Disabled"
End If
End Function

Tags:

Comments

( 3 comments — Leave a comment )
jelly_doughnut
Sep. 30th, 2005 12:08 pm (UTC)
See, after I learn Biblical Hebrew I'm going to post something like this so others can look and go "...huh?" COBOL was a long time ago wasn't it?
rialtus
Sep. 30th, 2005 03:17 pm (UTC)
You remember what COBOL stands for, right?

Compiles
Only
Because
Of
Luck
jelly_doughnut
Sep. 30th, 2005 05:11 pm (UTC)
Hehehe, yes indeed! That's why my degree is a Psychology degree! Compliance is not really an issue in the human service field!
( 3 comments — Leave a comment )