Page 2 of 3 <123>
Topic Options
#141660 - 2005-06-15 07:17 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
I did - doesn't work - just quickly blinks the screen and that is it. No error or anything. Almost like it doesn't run.
Top
#141661 - 2005-06-15 07:20 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
Well what i mean is no difference than before - expected expression. I am using the last code posted on the fnLDAPQuery link and I am using the code posted below:

Call "fnLDAPQuery.kix"

$=SetOption("WrapAtEOL","on")
$=SetOption("NoVarsInStrings","on")
;$=SetOption("Explicit","on")

Dim $sWhat,$sFrom,$sFilter,$sScope,$aResults,$Result,$R,$

$sWhat = "ADsPath","Name","department","physicalDeliveryOfficeName"

$sFrom = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")

$sFilter = "(&(objectCategory=user)(Name=sh*))"

$sScope = "subtree"

$aResults = fnLDAPQuery($sWhat,$sFrom,$sFilter,"displayName ASC",$sScope)
@ERROR " : " @SERROR ?

For Each $Result In $aResults
If VarType($Result)>8192
For Each $R In $Result
$R ?
Next
Else
$Result ?
EndIf
Next


Edited by DJ Ballistic (2005-06-15 07:22 PM)

Top
#141662 - 2005-06-15 07:28 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
OK for some reason i had to specify my UDF call with my netlogon directory of my server. It is in the same directory so I don't understand that but now I am getting some output.

Sewer Plants - SCRWF - Operations
LDAP://CN=Shari Collins,OU=Users,OU=Planning & Zoning,OU=AdminBldg,OU=County Facilities,DC=sussexcounty,DC=net
Shari Collins

What I need and only what I need is on the first line:
Sewer Plants - SCRWF - Operations

The other strange thing is when I run that it is showing me a few entries. Should it do that when I run it?

Top
#141663 - 2005-06-15 07:57 PM Re: Please help
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You can adjust the query to return only what you need. Let me ask some questions...
  • Why do you need the information?
  • Do you need to collect this information from individual users, all users, or a specific group of users?
  • Does it have to run in the logon script or as an admin script?
  • Finally (for now), what specific information do you want returned? (I assumed the info from the first post; Office (which is physicalDeliveryOfficeName in LDAP), and Location (same in LDAP)?

Top
#141664 - 2005-06-15 07:59 PM Re: Please help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Quote:

Ok with Bryce's code though that is displaying or would be displaying a specific user. See what is going to happen is this. Our default logon script runs. Then just before it exits it is going to call this pc inventory script to retrieve this information and dump it into an SQL database. It all works except retrieving the office they are located in. So i will need it to pull the office that the current user logging on is in.




use the @fullname macro.

Top
#141665 - 2005-06-15 08:02 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
Ok

I need this information for our database of information on every user in our organization. We are pulling Full Name, Username, PCName, Office, and Dell Service Tag. We need this to check for upcoming warranty expiration on our systems and we need the Office to be able to notify the department of whose PCs they are. It is an admin script but it runs so fast we have it running with a logon script. I do need to collect this information for every user that executes the logon script. And the only information I want returned is the Office which is physicalDeliveryOfficeName. I need to be able to take that and define the variable for it and dump it to an SQL database just like the other information.

Top
#141666 - 2005-06-15 08:03 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
Bryce I am not sure your code is going to work or not. It seems like the closest I am getting is with Chris S' code. I am not 100% there yet but I can't make your code work at all.
Top
#141667 - 2005-06-15 08:15 PM Re: Please help
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
For one user from the logonscript...

Code:

$sWhat = "physicalDeliveryOfficeName"

$sFrom = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")

$sFilter = "(&(objectCategory=user)(samAccountName="+@USERID+"))"

$sScope = "subtree"

$aResults = fnLDAPQuery($sWhat,$sFrom,$sFilter,"displayName ASC",$sScope)

"My physicalDeliveryOfficeName is: " + $aResults[0] ?


Top
#141668 - 2005-06-15 08:17 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
OK I run that with calling that fnLDAPQuery at the top and it returns no result. It just says My physicalDeliveryOffice is: [Blank]
Top
#141669 - 2005-06-15 08:22 PM Re: Please help
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Verify that your samAccountName matches @USERID, if not change the script from samAccountName to just Name.
Top
#141670 - 2005-06-15 08:24 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
the samAccountName matches all @USERID's. Name doesn't work anyway I just tried that. But @USERID should be fine. It is just reporting nothing.
Top
#141671 - 2005-06-15 08:39 PM Re: Please help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Since we are dealing with an admin script and not a logon script...

Code:

$users = GetObject("LDAP://OU=Corporate,OU=CompanyA,DC=Company,DC=local")
$users.filter = Split("user")
For Each $user In $users
? $user.OfficeLocations
Next


Top
#141672 - 2005-06-15 08:41 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
It IS a logon script - but it is an admin script too. See as I posted earlier it runs so fast so I have it run every time at user logon. But it is an Admin type of script. It is almost there. Come on Chris. I can't see why it isn't pulling that info. the samAccountName always mateches the @USERID's in our organization.
Top
#141673 - 2005-06-15 08:59 PM Re: Please help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
It is a logon script... or it is an admin script... can't be both.

A logon script is what every user runs at logon, the script runs under the users security rights. (and I suspect that is what is causing some of your problems)

An admin script is normally ran only when needed, ran by an administrator, with all rights and privileges that being the admin entails.

I personally can’t see the need to pull the .officelocations field on every logon... doesn’t mean that there is not a need for this, just means that i can't see it.

You say you are trying to populate a database with this information. A simple admin script, ran when ever you need to refresh the database would be my preferred method, hell you could even schedule it to run on a regular basis if you need frequent updates.

Bryce

Top
#141674 - 2005-06-15 09:03 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
Ok we are migrating to desktop authority so i can call this script and have it run only 1 time per user if i wanted to and it will modify the results in the database. All of that is no big deal. I just cannot pull the Office field. Regardless if it is an admin script or a logon script none of the code provided works. I would say it is a logon script based on that an admin isn't going to run it manually. I do agree that we wouldn't really necessarilly need the office information populated at every logon but we do need this information for every user at least 1 time which I don't have accomplished yet.

Edited by DJ Ballistic (2005-06-15 09:07 PM)

Top
#141675 - 2005-06-15 09:13 PM Re: Please help
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I don't know what to say. It works for me. I even recopied fnLDAPQuery() from the post to make sure that I was running the same code as you.

From the General tab of my user account Office = OH01. From the following code...

Code:
$sWhat = "physicalDeliveryOfficeName"

$sFrom = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")

$sFilter = "(&(objectCategory=user)(samAccountName="+@USERID+"))"

$sScope = "subtree"

$aResults = fnLDAPQuery($sWhat,$sFrom,$sFilter,"displayName ASC",$sScope)

"My physicalDeliveryOfficeName is: " + $aResults[0] ?

Get $

Function fnLDAPQuery($What,$From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
Dim $oCon,$oCMD,$oRS,$sQ,$sF,$sGV,$R,$vP,$aR[0],$nul

If $Scope <> "base" AND $Scope <> "onelevel" AND $Scope <> "subtree" $Scope = "subtree" EndIf

$sQ = "<"+$From+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+$Scope

If VarType($What)>8192
For Each $sF in $What $sGV=$sGV+'$'+'oRS.Fields("'+$sF+'").Value,' Next
$sGV=Substr($sGV,1,Len($sGV)-1)
Else
$sGV='$'+'oRS.Fields("'+$What+'").Value'
EndIf

$oCon=CreateObject("ADODB.Connection")
$oCon.Provider = "ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")

$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0

If $OrderBy="distinguishedName"
$oRS = CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS = $oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

Do
$nul=Execute('$'+'vP='+$sGV)
$aR[$R]=$vP
$oRS.MoveNext
$R=$R+1
ReDim Preserve $aR[$R]
Until $oRS.EOF
ReDim Preserve $aR[$R-1]
$fnLDAPQuery=$aR
EndFunction



My results are:

My physicalDeliveryOfficeName is: OH01

Top
#141676 - 2005-06-15 09:24 PM Re: Please help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Try installing KiXforms and running this other script from Chris. It will find the correct AD path for you for testing.

KiXforms - Active Directory Browser

KiXforms Home Page

Latest version of KiXforms download
 

Top
#141677 - 2005-06-15 09:40 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
I just don't get it. I'd rather not user KixForms for now. But I am using the same code you posted as well Chris. Do I not need to call ehat fnLDAPQuery.udf anymore? I was still calling that but it still doesn't work whether I call it or not. What could be wrong?

Edited by DJ Ballistic (2005-06-15 09:42 PM)

Top
#141678 - 2005-06-15 10:03 PM Re: Please help
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Chris's original code was using

Call "fnLDAPQuery.kix"

which actually calls a kix script that has the function in it. If you don't have that script, it won't do anything for you. So you need to actually put the function in your script like in Chris's last post.

If you haven't yet, i'd suggest reading How to use UDFs

Top
#141679 - 2005-06-15 10:13 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
Yeah I have that. Just not reporting anything in the results.
Top
Page 2 of 3 <123>


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

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.072 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

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