Page 1 of 1 1
Topic Options
#204053 - 2012-01-11 11:27 AM vBscript AD lookup
sparkie Offline
Getting the hang of it

Registered: 2010-09-14
Posts: 92
Loc: UK
Does anyone know of some vBscript that will lookup an AD user field (e.g City objUser.l) and if this is population with an equal entry, do something.

E.g

If user field (city) = "London" then
do
else

Thanks

Mark

Top
#204054 - 2012-01-11 11:52 AM Re: vBscript AD lookup [Re: sparkie]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4648
Loc: The Netherlands
No VBScript here as this is a forum about kixtart. In kix is not so difficult.

 Code:
$oDomain = GetObject("WinNT://" + @LDomain)
$oDomain.filter = "User", ""

For Each $user in $oDomain
	$username = $user.name
	$userhome = TranslateName(3, "", 3, @LDomain + "\" + $username, 1)
	$userinfo = GetObject("LDAP://" + $userhome[0])
	If $userinfo.l = "SomeCity"
		;Do something
	Else
		;Do something Else
	EndIf
Next


;FUNCTION TranslateName()
;
;AUTHOR
;			Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION
;			2.0
;
;ACTION
;			Translates from one name type to another. Good for converting an NT4 name
;			like domain\user into an LDAP distinguished name or the reverse.
;
;SYNTAX
;			TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
;
;PARAMETERS
;			$InitType (Required)
;				-  Integer value
;				1 = ADS_NAME_INITTYPE_DOMAIN
;				Initializes a NameTranslate object by setting the domain that the object will bind to.
;
;				2 = ADS_NAME_INITTYPE_SERVER
;				Initializes a NameTranslate object by setting the server that the object will bind to.
;
;				3 = ADS_NAME_INITTYPE_GC
;				Initializes a NameTranslate object by locating the global catalog to which the object
;				will bind.
;
;			$BindName (Required)
;				-  String value
;				If an $InitType = 3 (ADS_NAME_INITTYPE_GC), then the $BindName = "".
;				InitTypes 1 And 2 require a name of a domain Or server to be input. 
;				Note: "" may default to the current server or domain.
;
;			$LookupNameType (Required)
;				-  Integer value
;
;			$LookupName (Required)
;				-  String value see below
;
;			$ReturnNameType (Required)
;				-  Integer value see below
;
;				Documentation of Name Types. Lookup the more info on http://MSDN.Microsoft.com
;				Not all name types work. "1", "2", and "3" have been the most useful. 
;
;				1 = ADS_NAME_TYPE_1779
;				Name format as specified in RFC 1779. For example, "CN=Jane Doe,CN=users, DC=Microsoft, DC=com".
;
;				2 = ADS_NAME_TYPE_CANONICAL
;				Canonical name format. For example, "Microsoft.com/Users/Jane Doe".
;
;				3 = ADS_NAME_TYPE_NT4
;				Account name format used in Microsoft® Windows© NT® 4.0. For example, "Microsoft\JaneDoe".
;
;				4 = ADS_NAME_TYPE_DISPLAY
;				Display name format. For example, "Jane Doe".
;
;				5 = ADS_NAME_TYPE_DOMAIN_SIMPLE
;				Simple domain name format. For example, "JaneDoe@Microsoft.com".
;
;				6 = ADS_NAME_TYPE_ENTERPRISE_SIMPLE
;				Simple enterprise name format. For example, "JaneDoe@Microsoft.com".
;
;				7 = ADS_NAME_TYPE_GUID
;				Global Unique Identifier format. For example, {95ee9fff-3436-11d1-b2b0-d15ae3ac8436}.
;
;				8 = ADS_NAME_TYPE_UNKNOWN
;				Unknown name type. The system will try to make the best guess.
;
;				9 = ADS_NAME_TYPE_USER_PRINCIPAL_NAME
;				User principal name format. For example, "JaneDoe@Fabrikam.com".
;
;				10 = ADS_NAME_TYPE_CANONICAL_EX
;				Extended canonical name format. For example, "Microsoft.com/Users Jane Doe".
;
;				11 = ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME
;				Service principal name format. For example, "www/www.microsoft.com@microsoft.com"
;
;				12 = ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME
;				A SID string, as defined in the Security Descriptor Definition Language (SDDL), for either
;				the SID of the current object or one from the object's SID history.
;				For example, "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)" For more information see
;				Security Descriptor String Format under "Security" in the Microsoft Platform SDK documentation.
;
;REMARKS
;			Not name types seem to work.
;
;RETURNS
;			This function returns an ARRAY of three values:
;				Name of the type specified by $ReturnNameType (String)
;				Error number (Long Integer)
;				Error text (String).
;
;DEPENDENCIES
;			OS: Active Directory aware client
;
;EXAMPLES
;			$DN = TranslateName (3, "", 3, "@Domain\@wksta$", 1)
;			? "DN = " + $DN[0]
;			? "Error = " + $DN[1]
;			? "ErrorText = " + $DN[2]
;
;			$DN = TranslateName (3, "", 3, "@LDomain\@userid", 1)
;			? "DN = " + $DN[0]
;			? "Error = " + $DN[1]
;			? "ErrorText = " + $DN[2]
;
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


Edited by Mart (2012-01-11 03:05 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204055 - 2012-01-11 01:36 PM Re: vBscript AD lookup [Re: Mart]
sparkie Offline
Getting the hang of it

Registered: 2010-09-14
Posts: 92
Loc: UK
Cheers Mart,

I performed a search first in this forum relating to vBscript and found some other queries relative, so thought I would asked.

Thanks for this, something to ponder over.

Top
#204056 - 2012-01-11 05:19 PM Re: vBscript AD lookup [Re: sparkie]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2082
Loc: Tulsa, OK
Also see the fnLDAPQuery() function.
Top
Page 1 of 1 1


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

Who's Online
0 registered and 162 anonymous users online.
Newest Members
Jodey, Hiker, GTRoberts, KatieQuinn, Brennnnn
17684 Registered Users

Generated in 0.029 seconds in which 0.012 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