#157365 - 2006-02-17 08:46 AM
AD Scripting User Information
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
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 - 2006-02-17 10:08 AM
Re: AD Scripting User Information
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
|
Top
|
|
|
|
#157367 - 2006-02-17 10:11 AM
Re: AD Scripting User Information
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
Top
|
|
|
|
#157368 - 2006-02-17 10:14 AM
Re: AD Scripting User Information
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
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 (2006-02-17 09:33 PM)
|
Top
|
|
|
|
#157369 - 2006-02-17 10:15 AM
Re: AD Scripting User Information
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
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 - 2006-02-17 11:26 AM
Re: AD Scripting User Information
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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 - 2006-02-17 02:27 PM
Re: AD Scripting User Information
|
Chris S.
MM club member
Registered: 2002-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. (2006-02-17 02:29 PM)
|
Top
|
|
|
|
#157372 - 2006-02-17 03:04 PM
Re: AD Scripting User Information
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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 - 2006-02-17 04:20 PM
Re: AD Scripting User Information
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
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
|
|
|
|
#171557 - 2006-12-15 02:14 PM
Re: AD Scripting User Information
[Re: Richard H.]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
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....
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
|
|
|
|
#175042 - 2007-03-28 07:45 PM
Re: AD Scripting User Information
[Re: Wasim]
|
Howard Bullock
KiX Supporter
Registered: 2000-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 (2007-03-28 07:46 PM)
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|