#209478 - 2014-10-03 04:56 AM
Active Directory Properties
|
Jasniel
Getting the hang of it
Registered: 2000-04-08
Posts: 77
|
Hi
Is there a list of synteax that I can use to call for the fields within the user properties?
Example: Job Title, Department, Company, Telephone Number, etc.
|
|
Top
|
|
|
|
#209481 - 2014-10-03 09:30 AM
Re: Active Directory Properties
[Re: Lonkero]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
This may also help a bit 
CLS
Break on
$username = @USERID
$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
? 'Press a key...'
Get $
; 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
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
#209482 - 2014-10-03 09:41 AM
Re: Active Directory Properties
[Re: Mart]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Talk about silver platters... here's a script I wrote to enumerate all available properties in your AD.
ListAdsiToTxt("DOMAIN\username","@SCRIPTDIR\username.txt")
Function ListAdsiToTxt($strADObject, $strLogFile)
Global $objLog
Dim $objCN, $objLDAP, $objLDAPSchema, $objFSO, $objProperty
$objCN = TranslateName($strADObject)
$objLDAP = GetObject("LDAP://" + $objCN)
$objLDAPSchema = GetObject($objLDAP.schema)
$objFSO = CreateObject("Scripting.FileSystemObject")
$objLog = $objFSO.OpenTextFile($strLogFile, 8, 1)
$objLog.WriteLine("Mandatory Properties:")
$objLog.WriteLine("---------------------")
$objLog.WriteLine("")
For Each $objProperty In $objLDAPSchema.MandatoryProperties
If NOT InStr($objProperty,"-")
$=Execute("$$strPropType=VarTypeName($$objLDAP."+$objProperty+")")
$=Execute("$$strPropValue=$$objLDAP."+$objProperty)
$s = ""
Select
Case $strPropType = "Object"
WriteLog($objProperty,$strPropType)
Case $strPropType = "Variant[]"
WriteLog($objProperty,$strPropType)
For Each $item In $strPropValue
WriteLog("*"+$objProperty,$strPropType,$item)
Next
Case $strPropType = "Byte[]"
$comma = ""
For $i=0 to Len($strPropValue)
$s=$s+$comma+Right("0"+DecToHex(Asc(SubStr($strPropValue,$i,1))),2)
$comma = ","
Next
WriteLog($objProperty,$strPropType,$s)
Case 1
WriteLog($objProperty,$strPropType,$strPropValue)
EndSelect
Else
WriteLog($objProperty,"N/A")
EndIf
Next
$objLog.WriteLine("")
$objLog.WriteLine("Optional Properties:")
$objLog.WriteLine("--------------------")
$objLog.WriteLine("")
For Each $objProperty In $objLDAPSchema.OptionalProperties
If NOT InStr($objProperty,"-")
$= Execute("$$strPropType=VarTypeName($$objLDAP."+$objProperty+")")
$= Execute("$$strPropValue=$$objLDAP."+$objProperty)
$s = ""
Select
Case $strPropType = "Object"
$objDate = Integer8Date($strPropValue)
WriteLog($objProperty,$strPropType,$objdate)
Case $strPropType = "Variant[]"
WriteLog($objProperty,$strPropType)
For Each $item In $strPropValue
WriteLog("*"+$objProperty,$strPropType,$item)
Next
Case $strPropType = "Byte[]"
$comma = ""
For $i=0 to Len($strPropValue)
$s=$s+$comma+Right("0"+DecToHex(Asc(SubStr($strPropValue,$i,1))),2)
$comma = ","
Next
WriteLog($objProperty,$strPropType,$s)
Case 1
WriteLog($objProperty,$strPropType,$strPropValue)
EndSelect
Else
WriteLog($objProperty,"N/A")
EndIf
Next
$objLog.Close
EndFunction
Function WriteLog($LineToWrite,$sType,Optional $sValue)
Select
Case Len($sType) < 9
$sType = $sType+Chr(9)+Chr(9)
Case Len($sType) >= 9
$sType = $sType+Chr(9)
Case 1
? "Other Type?"
EndSelect
Select
Case Len($LineToWrite) < 8
$objLog.WriteLine($LineToWrite+Chr(9)+Chr(9)+Chr(9)+Chr(9)+Chr(9)+$sType+$sValue)
Case Len($LineToWrite) >= 8 AND Len($LineToWrite) < 16
$objLog.WriteLine($LineToWrite+Chr(9)+Chr(9)+Chr(9)+Chr(9)+$sType+$sValue)
Case Len($LineToWrite) >= 16 AND Len($LineToWrite) < 24
$objLog.WriteLine($LineToWrite+Chr(9)+Chr(9)+Chr(9)+$sType+$sValue)
Case Len($LineToWrite) >= 24 AND Len($LineToWrite) < 32
$objLog.WriteLine($LineToWrite+Chr(9)+Chr(9)+$sType+$sValue)
Case Len($LineToWrite) >= 32
$objLog.WriteLine($LineToWrite+Chr(9)+$sType+$sValue)
Case 1
? "Other Len?"
EndSelect
EndFunction
Function TranslateName($NameToTranslate)
Dim $NameTranslate
$NameTranslate = CreateObject("NameTranslate")
$NameTranslate.Init(3,"")
$NameTranslate.Set(3,$NameToTranslate)
$TranslateName = $NameTranslate.Get(1)
EndFunction
Function Integer8Date($objDate,optional $lngBias)
Dim $lngHigh,$lngLow,$lngDate,$Pow,$l,$jdate,$lngYear,$lngMonth,$lngDay,$s,$m,$h
If NOT (VarType($objDate) & 9) Exit 87 EndIf
If VarType($lngBias)=0
$lngBias = Val(ReadValue("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\","ActiveTimeBias"))
If @ERROR Exit @ERROR EndIf
EndIf
$lngHigh = $objDate.HighPart
$lngLow = $objDate.LowPart
If $lngLow < 0 $lngHigh=$lngHigh+1 EndIf
If $lngHigh = 0 AND $lngLow = 0 $lngBias=0 EndIf
$Pow=2.0
For $l = 1 to 31 $Pow=2.0*$Pow Next
$lngDate = ((CDbl($lngHigh)*$Pow+$lngLow)/600000000-$lngBias)/1440
If $lngDate > 0
$jdate = 584389 + Fix($lngDate)
$lngYear = (100*(((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4))+
(100*($jdate+306)-25))/36525
$lngMonth = (5*(((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4)+
($jdate+306)-365*$lngYear-$lngYear/4)+456)/153
$lngDay = (((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4)+
($jdate+306)-365*$lngYear-$lngYear/4)-(153*$lngMonth-457)/5
If $lngMonth>12 $lngYear=$lngYear+1 $lngMonth=$lngMonth-12 EndIf
$lngMonth = Right("0"+$lngMonth,2)
$lngDay = Right("0"+$lngDay,2)
$s = Fix(86400.0 * ($lngDate-Fix($lngDate)))
$m = $s / 60
$s = $s mod 60
$h = $m / 60
$m = $m mod 60
$Integer8Date=''+$lngYear+'/'+$lngMonth+'/'+$lngDay+' '+$h+':'+Right("0"+$m,2)+':'+Right("0"+$s,2)
EndIf
EndFunction
|
|
Top
|
|
|
|
#209484 - 2014-10-03 10:07 AM
Re: Active Directory Properties
[Re: Arend_]
|
Jasniel
Getting the hang of it
Registered: 2000-04-08
Posts: 77
|
Thanks for all your help.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|