Page 1 of 1 1
Topic Options
#113247 - 2004-02-04 01:52 AM Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
Hi all,

Long time Kix user, first time poster, lousy COM coder. I am looking for a way to pull the Description information for an object from AD into a variable.

For example, I'd create a group called "Printer_P6500ps", and in the description field for the group I'd put "\\server1". Then when a user logged on, the login script would check their group membership for any starting with "Printer_", parse out the last part of the group name (P6500ps, in this case) and that would be their printer. Then, their script would pull the "Description" field for that group from AD and parse it to find "\\server1" and that would become their print server for that queue.

Some may say "Why not just keep a lookup list of print servers to pinters" or any number of other ways to do this. Well, we're already being mandated to create a printer group that contains the printer name, and include the print server name in the description field, so if I can grab both of these bits of information through Kix I never have to maintain a lookup list, and rarely ever have to touch the script. Wishful thinking? Make sense?

I've had a look through many of the COM posts on grabbing info from AD and some of the UDFs, but haven't found anything to grab the description field of a group. I'm hoping to decide whether to pursue this idea within the next day or so, or revert to my original lookup table concept, and therefore don't have too much time to learn a lot about COM. Any thoughts would greatly appreciated.

Thanks in advance.

Top
#113248 - 2004-02-04 02:22 AM Re: Need to get object's Description from AD
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Welcome to the board.

Try this, (fill in the blanks, CN is the container name, and DN is the domain name)

Code:

$CN="cn=_____,ou=______"
$DN="dc=_____,dc=com"
$Group=getobject("LDAP://" + $CN + "," + $DN)
? $Group.get("Description")



I've really struggled with the com issues too. One of the best books I've found on it is Microsoft Windows 2000 Scripting Guide . All the examples are in vbscript, but are easily converted to kix.

Top
#113249 - 2004-02-04 05:25 AM Re: Need to get object's Description from AD
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Check out the Active Directory Cookbook. Examples are vbscript and perl.
_________________________
Eric

Top
#113250 - 2004-02-04 02:46 PM Re: Need to get object's Description from AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try reviewing this thread to see if this approach may be easier.


Printer mapping - modification of Howard's script based on group membership
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#113251 - 2004-02-04 08:07 PM Re: Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
Thanks for all the suggestions. I'm just poking at Al_po's suggested code bit now. I'll have a look at the other readings too.

Top
#113252 - 2004-02-04 09:00 PM Re: Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
Al_po, I tried your code, but all I get returned each time is the word "Description" (I'm assuming from the $Group.Get("Description") line). I don't think there's any problems with my "$CN=...$DN=" stuff because I copied it from a GPResult output (but you never know ). I'll start looking at the reference materials mentioned in this thread, but if you have any thoughts......
Top
#113253 - 2004-02-04 09:04 PM Re: Need to get object's Description from AD
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Might be a misplaced quote. Are you using KiXtart v4.x for COM?
_________________________
There are two types of vessels, submarines and targets.

Top
#113254 - 2004-02-04 09:07 PM Re: Need to get object's Description from AD
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Add some error checking...

Code:
 
$CN="cn=_____,ou=______"
$DN="dc=_____,dc=com"
$Group=getobject("LDAP://" + $CN + "," + $DN)
? @error
? @serror
? $Group.get("Description")



Top
#113255 - 2004-02-04 09:26 PM Re: Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
SeaLeopard, using Kix 4.22.

Al_Po, After including the error checking (why didn't I think of that ) I found my issue, and it was with my CN= entry. I had my CN equal to the final OU instead of equal to the Group inside that OU !!

I can now get the Description into a variable. Now just have to write the stuff to parse out the print server. It's a thing of beauty. I'm well on my way now, thanks for the assistance and lessons in COM. I'll post my final code once I pretty it up.

Top
#113256 - 2004-02-04 09:37 PM Re: Need to get object's Description from AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
How are you going to get the DN for your bind during script execution? You mentioned copying it from GPResult.

Look at TranslateName() UDF it will return the DN for you given the domain\groupname.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#113257 - 2004-02-04 10:36 PM Re: Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
Well, I just copied the DN from GPResult this time, to make sure I had the correct syntax, spelling, spacing, etc. The only part of the DN that will change in my process is the "cn=" value. The OU's will stay the same.

My plan was to do an ArrayEnumGroup() (thanks Jens), parse for all printer groups (Our naming standard for printer groups is "PRT_A_<queuename>" so easy to look up) then pass each of those names to the GetObject code you supplied to get my Print server. Once I've got the Print server and the queue name (parsed from the name of the group) I'll pass this to one of the MapPrinter UDFs (probably the one written by Jens because I like the 'alternate' print server option. Thanks again, Jens).

So crazy it just might work! Not as crazy as Asteroids Written in Kix , mind you.

Do you see any inefficiencies, like too many trips to Active Directory? Would it be better to use the TranslateNames() UDF and pass in the group name?

Top
#113258 - 2004-02-05 12:47 AM Re: Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
Hmmm, I was under the impression that COM would work fine for a Windows NT 4 workstation too if ADSI is installed, but I receive "-2147024846 The network request is not supported". Here's the code:

Code:
 $CN="cn=PRT_A_P1000,ou=groups,ou=Print,ou=Shared Services"
$DN="dc=*****,dc=COM"
$Group=getobject("LDAP://" + $CN + "," + $DN)
? @error
? @serror?
$Desc= $Group.Get("Description")



(Note, I blanked out the DC entry here)

Works perfect on my XP workstation and my 2K Terminal Server, but not NT 4. ADSI v2.5 is installed, according to the registry. Any ideas?

Top
#113259 - 2004-02-05 01:55 AM Re: Need to get object's Description from AD
Steve_B Offline
Fresh Scripter

Registered: 2004-02-04
Posts: 15
If you poke at this stuff long enough it starts to make sense.

So, is this the correct way of approaching a mixed XP/2K/NT environment something like this pseudocode?

If OpSys is XP or OpSys is 2K
$Group=getobject("LDAP://" + $CN + "," + $DN)
Else
$Group=getobject("WinNT://<domain>/<group>")
Endif

or is there a more elegant way? Or should I just always use the "WinNT://" method since it seems to work on all platforms?

Top
#113260 - 2004-02-05 06:23 AM Re: Need to get object's Description from AD
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, if you get the same data on winnt provider, I think you should use it.
IMHO, it's lot simpler too.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 595 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.121 seconds in which 0.092 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