Avatar of MSSC_support
MSSC_support
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Exporting active directory computer descriptions to local machines

Is there a way to export the computer descriptions from active directory into the local machines on our domain? We currently use logmein in our environment but when we try to use the LAN feature, although our AD descriptions are filled in with relevant information, this information is not on the local machines and therefore we have to use an extra step to find out the description.

Microsoft SQL Server 2008Active DirectoryWindows Server 2003

Avatar of undefined
Last Comment
ZephyrTC

8/22/2022 - Mon
gtworek

If I correctly understand your need you can create a script using "dsget computer -desc" to get computer descriptions from AD and "net config server /srvcomment" to set descriptions locally.
Details depend on your scenario.
ASKER CERTIFIED SOLUTION
ZephyrTC

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
MSSC_support

ASKER
OK I'm not too savvy with scripts. But I do know my way around it. In the first script. Is there anything i need to change in there? Such as after the LDAP?
MSSC_support

ASKER
Also, Will this work as a .bat script? Or must it be fixed as a vbscrpt?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ZephyrTC

The first script is set to go.  just run it from the machine you want to update.

Will only work as a vbscript, but you can also create a bat file to call the vb.

The bat would look like this, if you saved the vbs file to c:\changeComputerDescription.vbs
wscript.exe c:\changeComputerDescription.vbs

Open in new window

MSSC_support

ASKER
Right, running it as a VBScript I get the following error.

 Error
ZephyrTC

My apologies.  It is what should be expected of a script designed and tested at 3 in the morning.

This one should work great.  sorry for the inconvenience.

Dim objSysInfo, objUser, objComputer, Obj

'Get AD Info
set objSysInfo = CreateObject("ADSystemInfo")

Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)


'Set Local Computer Description
dim objNetwork
Set objNetwork = CreateObject("Wscript.Network")

strComputer = objNetwork.ComputerName

Set Obj = GetObject("winmgmts:\\" & strComputer & "\root\cimv2").InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = objComputer.Description
x.Put_
Next

Open in new window


You an optionally set the strComputer to = "." if you are running on local machines, but using the computer name setup allows you to integrate the text file line reader (second script posted) to essentially create an administrative tool.  Please let me know if you need further help or have any questions about modifying the script.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
MSSC_support

ASKER
3am?! Its 4 PM here! But, Perfect it worked!!! But I know had a light bulb moment! Is there a way to maybe do a script for the computer description based on who is logged on to the machine at the time?

ZephyrTC

I always say if you can dream it, you can do it.

What exactly are you thinking of?
MSSC_support

ASKER
Basically, we work in a domain environment and our remote access system displays the description of the local machine. We want this description to be the user who is logged on to the machine. So, we can set at login a script to rename the computer description to the user that is currently logged into the PC. By doing this, we can see from our remote software a way of finding out who is using that computer.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
MSSC_support

ASKER
additionally i have a script here that tells me the username based on the hostname i put into the script. So if i change the hostname to a live domain pc it will give me the user using it.

strComputer = "hostname"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
 
For Each objComputer in colComputer
    Wscript.Echo "Logged-on user: " & objComputer.UserName
Next
      

Is there a way to reverse this and get the PC name based on who is logged in?
MSSC_support

ASKER
I have found the following code to do the trick online but it does not seem to work.


 Set objExec = objShell.Exec("NETSH WINS SERVER \\winsservername SHOW NAME

where \\winservername is the win server for our environment
Option Explicit

Dim objShell, objExec, strUserName, strOutput, intLine
Dim intPosition, strIP, arrEntrySplit, strComputerName, intRemote

Set objShell = CreateObject("WScript.Shell")
strUserName = InputBox("Please enter a user name:" & vbCRLF & vbCRLF & _
   "(Press [ENTER] or click [CANCEL] to exit...)", _
   "User Computer Name Locator", "")

Do While strUserName <> ""
   Set objExec = objShell.Exec("NETSH WINS SERVER \\winsservername SHOW NAME " _
      & strUserName & " 03")
   For intLine = 1 To 4
      objExec.StdOut.ReadLine
   Next
   If objExec.StdOut.ReadLine <> "The name does not exist in 
the WINS database." Then
      For intLine = 1 To 5
         objExec.StdOut.ReadLine
      Next
      strOutput = objExec.StdOut.ReadLine
      If Left(strOutput,10) <> "IP Address" Then
         strOutput = objExec.StdOut.ReadLine
      End If
      intPosition = InStr(strOutput, ":")
      strIP = Right(strOutput, (Len(strOutput) - intPosition) - 1)
      Set objExec = objShell.Exec("NBTSTAT -A " & strIP)
      Do While Not objExec.StdOut.AtEndOfStream
         strOutput = objExec.StdOut.ReadLine
         If InStr(strOutput,"<03>") <> 0 Then
            arrEntrySplit = Split(strOutput)
            If UCase(arrEntrySplit(4)) <> UCase(strUserName) And _
               UCase(arrEntrySplit(4)) <> UCase(strComputerName) And _
               UCase(arrEntrySplit(4)) <> strComputerName & "$" Then
               strComputerName = strComputerName & UCase(arrEntrySplit(4))
            End If
         End If
      Loop
      If strComputerName <> "" Then
         MsgBox "The requested user '" & strUserName & _
            "' is logged on to: " & strComputerName,,"User Computer Name Locator"
      Else
         MsgBox "The requested user '" & strUserName & _
            "' doesn't appear to logged on to the network. "
      End If
   Else
      MsgBox "The user was not found in the WINS database. ",, _
         "User Computer Name Locator"
   End If
   strComputerName = ""
   strUserName = InputBox("Please enter a user name:" & vbCRLF & vbCRLF & _
      "(Press [ENTER] or click [CANCEL] to exit...)", _
      "User Computer Name Locator", "")
Loop

Open in new window

ZephyrTC

That's easy.  We simply add the currently logged in user to the computer description in the current script.  
Are you needing the local description to be modified, or the AD computer account description to be modified?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ZephyrTC

Starting with easy:  Here's how to get the local computer description to update with the AD description AND username.

Dim objSysInfo, objUser, objComputer, Obj

'Get AD Info
set objSysInfo = CreateObject("ADSystemInfo")

Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)


'Set Local Computer Description
dim objNetwork
Set objNetwork = CreateObject("Wscript.Network")

strComputer = objNetwork.ComputerName

Set Obj = GetObject("winmgmts:\\" & strComputer & "\root\cimv2").InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = objComputer.Description & "Logged In: " & objNetwork.UserName
x.Put_
Next

Open in new window


NOTE:  This will not update AD with the currently logged in user, just the local description.
MSSC_support

ASKER
That worked perfectly. I will now run this in group policy. Thank you.

If someone can get the following code working for me also that would be great:

 
Option Explicit

Dim objShell, objExec, strUserName, strOutput, intLine
Dim intPosition, strIP, arrEntrySplit, strComputerName, intRemote

Set objShell = CreateObject("WScript.Shell")
strUserName = InputBox("Please enter a user name:" & vbCRLF & vbCRLF & _
   "(Press [ENTER] or click [CANCEL] to exit...)", _
   "User Computer Name Locator", "")

Do While strUserName <> ""
   Set objExec = objShell.Exec("NETSH WINS SERVER \\winsservername SHOW NAME " _
      & strUserName & " 03")
   For intLine = 1 To 4
      objExec.StdOut.ReadLine
   Next
   If objExec.StdOut.ReadLine <> "The name does not exist in 
the WINS database." Then
      For intLine = 1 To 5
         objExec.StdOut.ReadLine
      Next
      strOutput = objExec.StdOut.ReadLine
      If Left(strOutput,10) <> "IP Address" Then
         strOutput = objExec.StdOut.ReadLine
      End If
      intPosition = InStr(strOutput, ":")
      strIP = Right(strOutput, (Len(strOutput) - intPosition) - 1)
      Set objExec = objShell.Exec("NBTSTAT -A " & strIP)
      Do While Not objExec.StdOut.AtEndOfStream
         strOutput = objExec.StdOut.ReadLine
         If InStr(strOutput,"<03>") <> 0 Then
            arrEntrySplit = Split(strOutput)
            If UCase(arrEntrySplit(4)) <> UCase(strUserName) And _
               UCase(arrEntrySplit(4)) <> UCase(strComputerName) And _
               UCase(arrEntrySplit(4)) <> strComputerName & "$" Then
               strComputerName = strComputerName & UCase(arrEntrySplit(4))
            End If
         End If
      Loop
      If strComputerName <> "" Then
         MsgBox "The requested user '" & strUserName & _
            "' is logged on to: " & strComputerName,,"User Computer Name Locator"
      Else
         MsgBox "The requested user '" & strUserName & _
            "' doesn't appear to logged on to the network. "
      End If
   Else
      MsgBox "The user was not found in the WINS database. ",, _
         "User Computer Name Locator"
   End If
   strComputerName = ""
   strUserName = InputBox("Please enter a user name:" & vbCRLF & vbCRLF & _
      "(Press [ENTER] or click [CANCEL] to exit...)", _
      "User Computer Name Locator", "")
Loop

Open in new window

ZephyrTC

What are you trying to do with this code?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
MSSC_support

ASKER
This code basically prompts me when I run it for the username. I then enter it in and it returns to me the computer that the user is logged on to. It would be really useful for us to get this working from an I.T. support standpoint as we can find out straight away who is using what computer.
ZephyrTC

I have looked into this myself for another client.  To the best of my efforts, I have not found a solution to querying the domain for a user and having it return a computer name that the user is currently logged in to.
However, Spiceworks is a free utility for network management that can do just what you're looking for in that regard.

Also, a simple solution you could implement is a script to echo the computer name to the user.  Assuming you have them on the telephone when providing assistance, you could create a very simple VBS file or batch to pop up their computer name so they could relay the information.
MSSC_support

ASKER
Ok not to worry. The script we had working did not work when I loaded it on group policy as the users do not have admin rights to changed the computer description. I had placed it under the logon script for USER CONFIGURATION. I have moved it to COMPUTER CONFIGURATION now but will this work under these conditions?

Dim objSysInfo, objUser, objComputer, Obj

'Get AD Info
set objSysInfo = CreateObject("ADSystemInfo")

Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)


'Set Local Computer Description
dim objNetwork
Set objNetwork = CreateObject("Wscript.Network")

strComputer = objNetwork.ComputerName

Set Obj = GetObject("winmgmts:\\" & strComputer & "\root\cimv2").InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = objComputer.Description & "Logged In: " & objNetwork.UserName
x.Put_
Next

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
MSSC_support

ASKER
Ok Ignore that last comment about putting it in the Computer description. I need to know now how to add permissions for domain users to change their computer description to get this fully working.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.