This script scans the Network Neighborhood for computers, reads their computer descriptions, and copies them into the Active Directory.
It's useful for keeping a centralized database of workstation ownership
var sh = WScript.CreateObject("WScript.Shell"); var exec = sh.exec("net view"); while (!exec.StdOut.AtEndOfStream) { line = exec.StdOut.ReadLine(); var strstart = line.substring(0, 2); if (strstart == "\\\\") { var nameend = line.indexOf(" "); var computer = line.substring(2, nameend); copyDescription(computer); } } WScript.Echo(exec.Status); function copyDescription(computer) { WScript.Echo(computer); try { var wmiService = GetObject("winmgmts:\\\\" + computer + "\\root\\cimv2"); } catch (e) { WScript.Echo("not found"); return; } var colItems = wmiService.ExecQuery("Select * from Win32_OperatingSystem", "WQL", 0x30); var enumItems = new Enumerator(colItems); var objItem = enumItems.item(); description = objItem.Description; var objComputer = null; try { var objComputer = GetObject("LDAP://CN=" + computer + ",OU=Computers,DC=domain,DC=local"); } catch (e) { WScript.Echo("Couldn't find in the AD"); return; } if (description == "") { WScript.Echo("Description empty"); } else if (objComputer != null) { WScript.Echo(description); objComputer.Put("Description", description); objComputer.SetInfo(); } }