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!
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
>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: