MSSC_support
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.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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?
ASKER
Also, Will this work as a .bat script? Or must it be fixed as a vbscrpt?
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:\changeComputerDescripti on.vbs
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:\changeComputerDescripti
wscript.exe c:\changeComputerDescription.vbs
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.
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.
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
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.
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?
I always say if you can dream it, you can do it.
What exactly are you thinking of?
What exactly are you thinking of?
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.
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=imper sonate}!\\ " & 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?
strComputer = "hostname"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
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?
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
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
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?
Are you needing the local description to be modified, or the AD computer account description to be modified?
Starting with easy: Here's how to get the local computer description to update with the AD description AND username.
NOTE: This will not update AD with the currently logged in user, just the local description.
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
NOTE: This will not update AD with the currently logged in user, just the local description.
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:
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
What are you trying to do with this code?
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.
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.
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.
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Details depend on your scenario.