script to retrieve info from Active Directory

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Trying to do a simple script to display information for some computers on a domain which are locked down by group policy tightly such that the only way to see this would be by this script.
Im getting the local machine name from WMI and trying to pull the computer description from Active Directory, to display that description alongside other details. Everything works here except that AD info. I have other scripts which retrieve info from
AD, and can see it in my console. Not sure what Im doing wrong with the code here or if I should be approaching this in a different way. Any help appreciated!

<pre>On Error Resume Next
strComputer = "."

Set objShell = Wscript.CreateObject("Wscript.Shell")
Set colSystemEnvVars = objShell.Environment("System")
Set colUserEnvVars = objShell.Environment("User")
Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set oShell = CreateObject("Wscript.Shell")
Set WshSysEnv = oShell.Environment("PROCESS")
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > "

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( strQuery, "WQL", 48 )

samUser = objNetwork.UserName
computerName = objNetwork.ComputerName
sLogonServer = WshSysEnv("LOGONSERVER")

Set objCompDesc = GetObject( "LDAP://CN=xxx,OU=xxx,OU=xxx,DC=xxx,DC=xxx,DC=xxx" )
CompDesc = objCompDesc.Get("computerName.Description")

For Each objItem In colItems
If IsArray( objItem.IPAddress ) Then
If UBound( objItem.IPAddress ) = 0 Then
strIP = objItem.IPAddress(0)
Else
strIP = "IP Addresses: " & Join( objItem.IPAddress, "," )
End If
End If
Next

objShell.Popup "COMPUTER NAME : " & computerName & vbCrLF & "USERNAME : " & samUser

& vbCrLF & "LOGONSERVER : " & RIGHT(sLogonServer, LEN(sLogonServer)-2) & vbCrLF & "IP

ADDRESS : " & strIP & vbCrLF & "LOCATION : " & CompDesc & vbCrLF

& vbCrLF & "Click OK to close this window, or wait 60 seconds",60,"Client Info",vbInformation+vbOKOnly+vbDefaultButton1
Wscript.Quit [/code]

<br/>

View the full article
 
Back
Top