PDA

View Full Version : Enumerating machines (All)



dineshcooper
02-13-2004, 05:19 AM
HI
Is it at all possible to get a list of all machine names on a network using WSH and VBscript that
can be run from a central server.

I was thinking about writing a login script to push the names into a db on login, but i was wondering, instead, if this could be done running one script on a server to harvest all machine names of the machines that are active.


Any help would be greatly appreciated

<P ID="edit"><FONT class="small">Edited by dineshcooper on 02/13/04 05:43.</FONT></P>

cprasley
03-28-2004, 10:28 PM
If you get desperate you could use

var WshShell = WScript.CreateObject("WScript.Shell");
var oExec = WshShell.Run("cmd.exe /C net view &gt; wslist.txt");

and then read in the file.

dineshcooper
03-29-2004, 01:32 AM
Hi thanks for that, I actually found a nice way of doing this. the code follows but please note, do not run the script on a live environment without changing its output method or else you'll get hundreds of popups.



Dim GlobalName
Dim MyDomain
Dim oDomain
Dim strDomainName
Dim oComputer
Dim count
count = 0
Set GlobalName = GetObject("WinNT:")

For Each MyDomain in GlobalName

Wscript.Echo MyDomain.Name
Set oDomain = GetObject("WinNT://" & MyDomain.Name)
oDomain.Filter = Array("Computer")

For Each oComputer in oDomain
'** Displays each machine in the domain **
Wscript.Echo oComputer.Name
'Set objWMIService = GetObject("winmgmts:\\" & oComputer.Name & "\root\cimv2")
'Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
'Wscript.Echo "UserName: " & objItem.UserName
count = count + 1
Next
Wscript.Echo Count
Next