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!