Question : Finding the MAC address for for multiple computers

WHEN I RUN THIS SCRIPT i GET THE FOLLOW ERROR



C:\>getmacinfo.vbs /s:  c:\Temp\macs.txt  /l:"C:\Temp\my log file.txt

C:\>cscript getmacinfo.vbs /s:"c:\Temp\macs.txt" /l:"C:\Temp\logfile.txt"
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\getmacinfo.vbs(93, 25) Microsoft VBScript compilation error: Expected end of
statement


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
'USAGE:
'cscript getmacinfo.vbs /s:<source file> /l:<log file>
'
'/s     Enter the location of the source file containing computer names and/or IP addresses.  For example; /s:"c:\Temp\my file.txt"
'/l     Enter the location of the log file.  For example; /l:"C:\Temp\my log file.txt"
'
'Example:
'    cscript getmacinfo.vbs /s:"c:\Temp\my file.txt" /l:"C:\Temp\my log file.txt"
'
'COMMENTS:
'Features of this script;
'	This script will open a file containing computer names and/or IP addresses.
'	The script will run the command getmac against each line item from the file.
'	A log file will be created with the output.

Dim colNamedArguments
Dim strSource
Dim strLog

'Check that the script is running under cscript
checkforcscript()

'Get arguments from command line
Set colNamedArguments = WScript.Arguments.Named
strSource = colNamedArguments.Item("s")
strLog    = colNamedArguments.Item("l")

'Check for help key
if WScript.Arguments.Named.Exists("?") OR WScript.Arguments.Named.Exists("h") Then
	FoundError("ArgumentNotFound")
	wscript.quit 1
end if

if strSource = "" OR strLog = "" then
	FoundError("ArgumentNotFound")
	wscript.quit 1
end if

ReadFileAndExecuteScript()

Sub ReadFileAndExecuteScript()
	'Open the source file and read in all the lines
	Set objFSORead = CreateObject("scripting.filesystemobject")
	Set objReadFile = objFSORead.OpenTextFile(strSource, 1)
	strContents = objReadFile.ReadAll
	arrLines = Split(strContents,vbCRLF)
	objReadFile.Close
	'Create a new file that will be the converted CSV file
	Set objFSOWrite = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSOWrite.OpenTextFile(strLog, 2, True)
	for each strTarget in arrLines
		Set WshShell = WScript.CreateObject("WScript.Shell")
		Set WshExec = WshShell.exec("getmac /S " & strTarget & " /FO CSV /NH")
		'wait for getmac to finish
		do while WshExec.Status = 0
			wscript.sleep 100
		loop
		'write output to log file
		Do While Not(WshExec.StdOut.AtEndOfStream)
			strResults = WshExec.StdOut.ReadLine
			objFile.WriteLine """" & strTarget & """," & strResults
		Loop
	next
	objFile.Close
End Sub

Sub checkforcscript()
	'If not running under cscript, relaunch using command line
	Set oShell = CreateObject("Wscript.Shell")
	If Not WScript.FullName = wscript.Path & "\cscript.exe" Then
		oShell.Popup "Launched using wscript. Relaunching...",3,"WSCRIPT"
		oShell.Run "cmd.exe /k " & wscript.Path & "\cscript.exe //NOLOGO " & Chr(34) & wscript.scriptFullName & Chr(34) & " /?",1,False
		wscript.quit
	End If
End Sub

Sub FoundError(sCase)
	'Error messages
	select case sCase
		case "ArgumentNotFound"
			wscript.echo "cscript getmacinfo.vbs /s:<source file> /l:<log file>"
			wscript.echo ""
			wscript.echo "/s     Enter the location of the source file containing computer names and/or"
			wscript.echo "       IP addresses."
			wscript.echo "       For example; /s:""c:\Temp\my file.txt"""
			wscript.echo "/l     Enter the location of the log file."
			wscript.echo "       For example; /l:""C:\Temp\my log file.txt"""
			wscript.echo ""
			wscript.echo "Example:"
			wscript.echo "    cscript getmacinfo.vbs /s:""c:\Temp\my file.txt"" /l:""C:\Temp\my log file.txt"""
	end select
End Sub 
Toggle HighlightingOpen in New WindowSelect All

Answer : Finding the MAC address for for multiple computers

Rob is correct - I think you copied and pasted some extra text into your file.  Remove line 93 and the script I wrote you should work.

For reference here was the original question...
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26328590.html
Random Solutions  
 
programming4us programming4us