×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LDAP Description Query

LDAP Description Query

LDAP Description Query

(OP)
I am not a programmer or scriptor at nature but I have put together a small script that achieves what I want in theory but is not working in practice. My main goal is to have a text file on the local PC with the description from AD in it. This would be a login script so the text file would be updated everytime a user logs on.

So far, this is what I have:

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )    

On Error Resume Next

Set objComputer = GetObject _
    ("LDAP://CN=" & strComputerName & ",OU=Computers,OU=KGH COMPUTERS,DC=domain,DC=org")
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile("c:\Windows\Temp\descr.txt", True)
objProperty = objComputer.Get("Description")
If IsNull(objProperty) Then
    Wscript.Echo "The description has not been set."
Else
    file.WriteLine "" & objProperty
    objProperty = Null
End If


The part that does not work within this script is the ldap url, I cannot get this to work unless the computer specified is in the OU specified, it cannot be a sub. I've tried appending ??sub? to the end of the url but that does not work.

I am sure there is some extra language in this code that I do not need or there is a more efficient way to do this but I haven't been able to figure it out, any help would be appreciated!

RE: LDAP Description Query

[0]
>The part that does not work within this script is the ldap url,
What you say ldap url, I would guess it is called properly adspath.

[1]
>I cannot get this to work unless the computer specified is in the OU specified, it cannot be a sub.
Sub, what is it?

[2] The computer name so set in the environment is not necessary the cn of the computer. It could be, by coincidence, but not generally be. It is more of a netbios name. You can look into the IADsNameTranslate interface to make the proper search of the distinguished name of the computer (and hence, its adspath) and then bind with it to the directory to get the description. Check out the demo of how it is done here.
    http://www.rlmueller.net/NameTranslateFAQ.htm#How%20do%20I%20convert%20the%20NetBIOS%20name%20of%20a%20computer%20to%20its%20Distinguished%20Name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close