Page 1 of 1 1
Topic Options
#185519 - 2008-02-20 09:22 PM Display or getting Login-Script Name of current user from AD
Luziekix Offline
Getting the hang of it

Registered: 2003-02-27
Posts: 68
Hi,

is there a way to get the Value of the Login-Script-Field
in the users AD entries? E.g. with @COMMENT I can get the
"User comment" from the users AD entry. How can I get the
name of the Loginscript of the current user?

Regards,

Luziekix

Top
#185520 - 2008-02-20 09:27 PM Re: Display or getting Login-Script Name of current user from AD [Re: Luziekix]
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
Does the script run locally on the workstation?

The reason I ask is the @userid may work for you? Problem is the script needs to be running under the user that you want the user id from if I remember correctly.

Indigo


Edited by Indigoseth (2008-02-20 09:30 PM)

Top
#185522 - 2008-02-20 11:40 PM Re: Display or getting Login-Script Name of current user from AD [Re: Indigoseth]
DStelz Offline
Getting the hang of it

Registered: 2007-01-26
Posts: 72
Loc: Green Bay, WI
You would have to connect to your ldap database and pull out the scriptPath from the property of the user object. There is a way to traverse through the whole AD structure I think. Or you can do it with a login script to a text file or something like that.

I'd love to tell you how, but I don't have time to strum up exact code at the moment. There are some people around that it should be cake work for them.


Edited by DStelz (2008-02-20 11:42 PM)

Top
#185540 - 2008-02-21 08:19 AM Re: Display or getting Login-Script Name of current user from AD [Re: DStelz]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The script below is found at http://www.adminscripteditor.com/scriptlibrary/view.asp?id=261 I modified it a bit to only return the script path and to have the function not display stuff on the screen.

 Code:
$scriptpath = GetScriptpath("usernamegoeshere")
?$scriptpath
Sleep 2

Function GetScriptPath($ADAccountName)
	$filter=" where samAccountName='"+$ADAccountName+"' "
	$AdoCon = CreateObject("ADODB.Connection")
	$AdoCon.Provider = "ADsDSOObject"; Current credentials are used, as username and password aren't specified
	$AdoCon.Open("Active Directory Provider"); Create ADO command object for the connection.
	$AdoCommand = CreateObject("ADODB.Command")
	$AdoCommand.ActiveConnection = $AdoCon
	$AdoCommand.CommandText ="Select AdsPath, samAccountName, GroupType, Scriptpath, Department, " +
	"physicalDeliveryOfficeName from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
	;Other fields include: givenname, initials, sn, displayname, telephonenumber, wwwhomepage, url, postofficebox, postalcode, profilepath, homedrive
	;       homedirectory, homephone, pager, mobile, facsimiletelephonenumber, iphone, othertelephone, title, department, company, and others.

	; Execute the query.
	$Recordset = $AdoCommand.Execute
	$ADlookupname=$recordset.Fields("samAccountName").value
	If $ADlookupName <> $ADAccountName
		$GetScriptpath = 13
	Else
		$GetScriptpath = $recordset.fields("scriptpath").value
	EndIf
	$adocon="0"
	$adocommand="0"
	$recordset="0"
EndFunction


Edited by Mart (2008-02-21 08:21 AM)
Edit Reason: Split up the loooong line.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185543 - 2008-02-21 09:25 AM Re: Display or getting Login-Script Name of current user from AD [Re: Mart]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I think we can probably cut the code down a little bit as you are retrieving the information for the currently logged in user...
 Code:
$oADInfo=CreateObject("ADSystemInfo")
$oUser=GetObject("LDAP://"+$oADInfo.UserName)
"Scriptpath='"+$oUser.scriptPath+"'"+@CRLF

Top
#185599 - 2008-02-21 11:03 PM Re: Display or getting Login-Script Name of current user from AD [Re: Richard H.]
Luziekix Offline
Getting the hang of it

Registered: 2003-02-27
Posts: 68
Thanks lots to you all, this works for me!

Regards,

Luziekix

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 641 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.056 seconds in which 0.024 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