Page 1 of 1 1
Topic Options
#157365 - 06/02/17 08:46 AM AD Scripting User Information
Arend_ Moderator Offline
MM club member
*****

Registered: 05/01/17
Posts: 1815
Loc: Hilversum, The Netherlands
Since it can be somewhat of a pain to find out all of the user's properties I thought I'd make a list of what's most common. If anyone has anymore properties they'd like to see just make a post and I'll add it.

Code:

$username = "testusername"
$userhome = TranslateName (3, "", 3, "@LDomain\$username", 1)
$userinfo = GetObject("LDAP://" + $userhome[0])

? "General Info"
? "------------"
? " "
? "First Name: " + $userinfo.givenName
? "Initials: " + $userinfo.initials
? "Last Name: " + $userinfo.sn
? "Full Name: " + $userinfo.FullName
? "Display Name: " + $userinfo.displayName
? "Account Name: " + $userinfo.sAMAccountName
? "Distinguished Name: " + $userinfo.distinguishedName
? "Description: " + $userinfo.Description
? "Office Location: " + $userinfo.physicalDeliveryOfficeName
? "Email: " + $userinfo.mail
? "Web Page: " + $userinfo.wwwHomePage
? "Street: " + $userinfo.streetAddress
? "Postal Code: " + $userinfo.postalCode
? "Post Office Box: " + $userinfo.postOfficeBox
? "City: " + $userinfo.l
? "State or Province: " + $userinfo.st
? "Country or Region: " + $userinfo.co
? "Home Phone: " + $userinfo.homePhone
? "Pager: " + $userinfo.pager
? "Mobile Phone: " + $userinfo.mobile
? "Telephone Number: " + $userinfo.telephoneNumber
? "Fax Number: " + $userinfo.facsimileTelephoneNumber
? "Notes: " + $userinfo.info
? "Title: " + $userinfo.title
? "Department: " + $userinfo.department
? "Company Name: " + $userinfo.company
? "Principal Name: " + $userinfo.userPrincipalName
? " "
? "Profile Info"
? "------------"
? " "
? "Profile Path: " + $userinfo.profilePath
? "Script Path: " + $userinfo.scriptPath
? "Home Directory: " + $userinfo.homeDirectory
? "Home Drive: " + $userinfo.homeDrive
? "Terminal Services Profile Path: " + $userinfo.TerminalServicesProfilePath
? "Terminal Services Local Path: " + $userinfo.TerminalServicesHomeDirectory
? "Terminal Services Home Drive: " + $userinfo.TerminalServicesHomeDrive
? "Terminal Services Allowed: " + $userinfo.AllowLogon
? " "
? "Account Info"
? "------------"
? " "
? "User Account Control: " + $userinfo.userAccountControl
? "Account Disabled: " + $userinfo.AccountDisabled
? "Account Locked: " + $userinfo.IsAccountLocked
? "Account Created: " + $userinfo.whenCreated
? "Account Last Modified: " + $userinfo.whenChanged
? "Account Expires: " + $userinfo.AccountExpirationDate
? "Last Login: " + $userinfo.LastLogin
? "Last Failed Login: " + $userinfo.LastFailedLogin
? "Logon Count: " + $userinfo.logonCount
? "Bad Login Count: " + $userinfo.BadLoginCount
? "Password Last Changed: " + $userinfo.PasswordLastChanged

; TranslateName function authored by Howard A. Bullock
Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction


Top
#157366 - 06/02/17 10:08 AM Re: AD Scripting User Information
NTDOC Administrator Offline
Administrator
*****

Registered: 00/07/28
Posts: 11543
Loc: CA
Here are some links to get more information on the AD.


Administration and Management
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/setupsysadmin.asp

Active Directory Glossary
http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/glossary.asp

Binding to Active Directory
http://msdn.microsoft.com/library/defaul...e_directory.asp

Syntaxes for Active Directory Attributes
http://msdn.microsoft.com/library/defaul..._attributes.asp

All Attributes - The following attributes are defined by Active Directory.
http://msdn.microsoft.com/library/defaul...ributes_all.asp

Mappings for the Active Directory Users and Computers Snap-in
http://msdn.microsoft.com/library/defaul...ers_snap-in.asp

Top
#157367 - 06/02/17 10:11 AM Re: AD Scripting User Information
Radimus Moderator Offline
Moderator
*****

Registered: 00/01/06
Posts: 5186
Loc: Tampa, FL
http://www.kixtart.org/ubbthreads/showfl...part=2&vc=1
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#157368 - 06/02/17 10:14 AM Re: AD Scripting User Information
NTDOC Administrator Offline
Administrator
*****

Registered: 00/07/28
Posts: 11543
Loc: CA
Well this link has much more information on each attribute than just it's name as in that post.

All Attributes - The following attributes are defined by Active Directory.
http://msdn.microsoft.com/library/defaul...ributes_all.asp


Edited by NTDOC (06/02/17 09:33 PM)

Top
#157369 - 06/02/17 10:15 AM Re: AD Scripting User Information
NTDOC Administrator Offline
Administrator
*****

Registered: 00/07/28
Posts: 11543
Loc: CA
Dang 04:00 AM for you Rad, glad I don't work where you do, only 01:00 here and haven't gone to bed yet.
Top
#157370 - 06/02/17 11:26 AM Re: AD Scripting User Information
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
You could enumerate the properties. It's not as nicely categorised as your example, but it does pick up all the attributes and saves a lot of typing.

I left out the code to recursively expand objects and arrays as an exercise for the reader.

Code:
Break ON
$=SetOption("WrapAtEOL","ON")

$sUserName = "rhowarth"
$asUserHome = TranslateName (3, "", 3, @LDomain+"\"+$sUserName, 1)
$oUserInfo = GetObject("LDAP://" + $asUserHome[0])
$oUserClass = GetObject($oUserInfo.schema)

$iMaxLen=0
$sPropertyList=""

; Collate properties and determine max length to tidy up the display
For Each $sProperty in $oUserClass.MandatoryProperties
If Len($sProperty)>$iMaxLen $iMaxLen=Len($sProperty) EndIf
$sPropertyList=$sPropertyList+@CRLF+$sProperty
Next
For Each $sProperty in $oUserClass.OptionalProperties
If Len($sProperty)>$iMaxLen $iMaxLen=Len($sProperty) EndIf
$sPropertyList=$sPropertyList+@CRLF+$sProperty
Next

$iMaxLen=$iMaxLen+1
While Len($sSpacer)<$iMaxLen $sSpacer=$sSpacer+" " Loop

; Sort and enumerate the properties
For Each $sProperty in QS(Split(SubStr($sPropertyList,3),@CRLF))
If Instr($sProperty,"-") ; Skip properties that will cause KiXtart parser problems
Left($sProperty+$sSpacer,$iMaxLen)+"N/A"+@CRLF
Else
$=Execute("$$sVarType=VarTypeName($$oUserInfo."+$sProperty+")")
$=Execute("$$sVarValue=$$oUserInfo."+$sProperty)
Left($sProperty+$sSpacer,$iMaxLen)+Left($sVarType+$sSpacer,11)
Select
Case $sVarType="String"
$sVarValue
Case $sVarType="long"
$sVarValue
EndSelect
@CRLF
EndIf
Next

Exit 0

; TranslateName function authored by Howard A. Bullock
Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction

; BrianTX's Qsort.
function qs($a)
DIM $b[32],$c[32],$d,$e,$f,$g,$h,$i,$j,$k,$l
$b[0]=0
$c[0]=UBOUND($a)
$d=0
While $d >=0
$e=$b[$d]
$f=$c[$d]
While $e < $f
$h=$e+($f-$e)/2
$k=$a[$e]
$A[$e]=$A[$h]
$A[$h]=$k
$i=$e+1
$j=$f
$l=0
Do
While ($i<$j) AND $A[$e] > $A[$i]
$i=$i+1
Loop
While ($j>=$i) AND $A[$j] > $A[$e]
$j=$j-1
Loop
IF $i>=$j
$l=1
ELSE
$k=$A[$i]
$A[$i]=$A[$j]
$A[$j]=$k
$j=$j-1
$i=$i+1
ENDIF
Until $l=1
$k=$a[$e]
$a[$e]=$a[$j]
$a[$j]=$k
$g=$j
If $g-$e <= $f - $g
If $g+1 < $f
$b[$d]=$g+1
$c[$d]=$f
$d=$d+1
Endif
$f=$g-1
Else
If $g-1 > $e
$b[$d]=$e
$c[$d]=$g-1
$d=$d+1
Endif
$e=$g+1
Endif
Loop
$d=$d-1
Loop
$qs=$a
Endfunction


Top
#157371 - 06/02/17 02:27 PM Re: AD Scripting User Information
Chris S. Offline
MM club member
*****

Registered: 02/03/18
Posts: 2368
Loc: Earth
You could also use the AD Schema Browser I wrote to look at the property names (and the type of data they return) for every object in the schema.

http://www.kixtart.org/ubbthreads/showfl...true#Post146018


Edited by Chris S. (06/02/17 02:29 PM)

Top
#157372 - 06/02/17 03:04 PM Re: AD Scripting User Information
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
You just need to update it so the user can load an instance of the object and display the data
Top
#157373 - 06/02/17 04:20 PM Re: AD Scripting User Information
Arend_ Moderator Offline
MM club member
*****

Registered: 05/01/17
Posts: 1815
Loc: Hilversum, The Netherlands
NTDOC: Your last link doesn't work
For the rest, thanks for contibuting, this is exactly what I intended. With this thread every user looking for AD user info will get all the info they will need. Thank you all

Top
#157374 - 06/02/17 09:35 PM Re: AD Scripting User Information
NTDOC Administrator Offline
Administrator
*****

Registered: 00/07/28
Posts: 11543
Loc: CA
Not sure why but the board messed up the link. It was just a repost of one of the above links. All fixed now.
Top
#171557 - 06/12/15 02:14 PM Re: AD Scripting User Information [Re: Richard H.]
Arend_ Moderator Offline
MM club member
*****

Registered: 05/01/17
Posts: 1815
Loc: Hilversum, The Netherlands
I needed all properties written to a text file so first I started editing Richard's code for my private use but ended up rewriting the whole thing.
It's a bit messy, especially with the tab spaced WriteLog function.
But it works fine and the end result looks nice and this way you know ALL the users properties,types and values whether you have exchange or not you get the properties that are available to you.

Anyway without further ado....
Code:
Break ON
$=SetOption("WrapAtEOL","ON")

$usr = "apronk"
$logf = "D:\Schema.txt"

$cnusr = TranslateName($usr)
$usrnfo = GetObject("LDAP://" + $cnusr)
$usrclas = GetObject($usrnfo.schema)

$fso = CreateObject("Scripting.FileSystemObject")
$log = $fso.OpenTextFile($logf, 8, 1)

$log.WriteLine("Mandatory Properties:")
$log.WriteLine("---------------------")
$log.WriteLine("")

For Each $prop in $usrclas.MandatoryProperties
  If NOT Instr($prop,"-")
    $= Execute("$$Type=VarTypeName($$usrnfo."+$prop+")")
    $= Execute("$$Value=$$usrnfo."+$prop)
    If $type <> "Object" AND $type <> "Variant[]"
      WriteLog($prop,$type,$value)
    Else
      WriteLog($prop,$type)
    EndIf
  Else
    WriteLog($prop,"N/A")
  EndIf
Next

$log.WriteLine("")
$log.WriteLine("Optional Properties:")
$log.WriteLine("--------------------")
$log.WriteLine("")

For Each $prop in $usrclas.OptionalProperties
  If NOT Instr($prop,"-")
    $= Execute("$$Type=VarTypeName($$usrnfo."+$prop+")")
    $= Execute("$$Value=$$usrnfo."+$prop)
    If $type <> "Object" AND $type <> "Variant[]"
      WriteLog($prop,$type,$value)
    Else
      WriteLog($prop,$type)
    EndIf
  Else
    WriteLog($prop,"N/A")
  EndIf
Next

$log.Close

Function WriteLog($LineToWrite,$sType,Optional $sValue)
  If LEN($LineToWrite) < 8
    $log.WriteLine($LineToWrite + "					" + $sType + "		" + $sValue)
  EndIf
  If LEN($LineToWrite) >= 8 AND LEN($LineToWrite) < 16
    $log.WriteLine($LineToWrite + "				" + $sType + "		" + $sValue)
  EndIf
  If LEN($LineToWrite) >= 16 AND LEN($LineToWrite) < 24
    $log.WriteLine($LineToWrite + "			" + $sType + "		" + $sValue)
  EndIf
  If LEN($LineToWrite) >= 24 AND LEN($LineToWrite) < 32
    $log.WriteLine($LineToWrite + "		" + $sType + "		" + $sValue)
  EndIf
  If LEN($LineToWrite) >= 32
    $log.WriteLine($LineToWrite + "	" + $sType + "		" + $sValue)
  EndIf
EndFunction

Function TranslateName($NameToTranslate)
  Dim $NameTranslate
  $NameTranslate = CreateObject("NameTranslate")
  $NameTranslate.Init(3,"")
  $NameTranslate.Set(3, @LDOMAIN + "\" + $NameToTranslate)
  $TranslateName = $NameTranslate.Get(1)
EndFunction


Top
#171564 - 06/12/15 04:06 PM Re: AD Scripting User Information [Re: Arend_]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
could change your writelog to something like:
Code:
Function WriteLog($LineToWrite,$sType,Optional $sValue)
    $log.WriteLine($LineToWrite + "	" + 
     left(chr(9)+chr(9)+chr(9)+chr(9),(33>LEN($LineToWrite))*(32-LEN($LineToWrite))/8) +
     $sType + "		" + $sValue)
EndFunction
_________________________
!

download KiXnet

Top
#171574 - 06/12/15 05:38 PM Re: AD Scripting User Information [Re: Lonkero]
Arend_ Moderator Offline
MM club member
*****

Registered: 05/01/17
Posts: 1815
Loc: Hilversum, The Netherlands
It was never meant to be clean. It's quick and dirty and it works, thats all. If I clean it up I'll submit it as a totally clean script to the UDF section and then I'll surely implement your idea.

But for now it works fine as is.

Top
#171596 - 06/12/16 02:17 AM Re: AD Scripting User Information [Re: Arend_]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
is there something left for cleaning in my version still? ;\)
_________________________
!

download KiXnet

Top
#175037 - 07/03/28 05:40 PM Re: AD Scripting User Information [Re: Lonkero]
Wasim Offline
Fresh Scripter

Registered: 07/03/28
Posts: 7
hi i m trying to use this

Break ON
"Home Directory: " + $userinfo.homeDirectory
"Home Drive: " + $userinfo.homeDrive

but its not giving me any information am i doing something wrong? (win xp os)

Top
#175042 - 07/03/28 07:45 PM Re: AD Scripting User Information [Re: Wasim]
Howard Bullock Offline
KiX Supporter
*****

Registered: 00/09/15
Posts: 5809
Loc: Harrisburg, PA USA
You need to bind to an AD object before you can access object properties.

This is an old thread. Maybe you should start your own thread.


Edited by Howard Bullock (07/03/28 07:46 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Shawn) and 90 anonymous users online.
Newest Members
B1GHawkeyes, GeoHamm, register, Marcus_Dunne, stuvwx656262
17397 Registered Users

Generated in 0.373 seconds in which 0.331 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org