Board index » Visual Studio » IPCONFIG /ALL Script... something missing

IPCONFIG /ALL Script... something missing

Visual Studio352
All-



I am trying to write up a small VBScript that will run the ipconfig

/all command on a list of servers in a text file and output the

results to another text file.



I've run into one issue. When I run the script, instead of writing

all of the ipconfig /all results to the output file, it writes the

results of the first server only (and it repeats that for however many

servers I have in the input file).



Here is what I have now:



Const ForAppending = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile _

("c:\results.txt", ForAppending, True)

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile =



objFSO.OpenTextFile(INPUT_FILE_NAME,FOR_READING)

strComputers = objFile.ReadAll

objFile.Close

arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Set objShell = CreateObject("WScript.Shell")

Set objScriptExec = objShell.Exec("ipconfig /all")

strIpConfig = objScriptExec.StdOut.ReadAll

For Each ??????????????????????

objTextFile.WriteLine(strIpConfig)

Next

Next

objTextFile.Close



------------



The line containing "For Each ??????????????????????" is the line

where I know I'm missing the For Each.. but I can't seem to get it

right.



Any ideas?



Thanks.


-
 

Re:IPCONFIG /ALL Script... something missing

BS_WTF_123 wrote:

Quote
All-



I am trying to write up a small VBScript that will run the ipconfig

/all command on a list of servers in a text file and output the

results to another text file.



I've run into one issue. When I run the script, instead of writing

all of the ipconfig /all results to the output file, it writes the

results of the first server only (and it repeats that for however many

servers I have in the input file).



Here is what I have now:



Const ForAppending = 2





Const ForAppending = 8



OpenTextFile Method

msdn.microsoft.com/library/en-us/script56/html/jsmthopentextfile.asp">msdn.microsoft.com/library/en-us/script56/html/jsmthopentextfile.asp



WSH 5.6 documentation download

http://www.microsoft.com/downloads/details.aspx?FamilyId" rel="nofollow" target="_blank">www.microsoft.com/downloads/details.aspx=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en







Quote
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile _

("c:\results.txt", ForAppending, True)

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile =



objFSO.OpenTextFile(INPUT_FILE_NAME,FOR_READING)

strComputers = objFile.ReadAll

objFile.Close

arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Set objShell = CreateObject("WScript.Shell")

Set objScriptExec = objShell.Exec("ipconfig /all")

strIpConfig = objScriptExec.StdOut.ReadAll

For Each ??????????????????????

objTextFile.WriteLine(strIpConfig)

Next

Next

objTextFile.Close



------------



The line containing "For Each ??????????????????????" is the line

where I know I'm missing the For Each.. but I can't seem to get it

right.



Any ideas?



Thanks.



--

Michael Harris

Microsoft.MVP.Scripting



Windows 2000 Scripting Guide

Microsoft® Windows®2000 Scripting Guide

www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp">www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp



TechNet Script Center Sample Scripts

http://www.microsoft.com/downloads/release.asp?ReleaseID" rel="nofollow" target="_blank">www.microsoft.com/downloads/release.asp=38942





-

Re:IPCONFIG /ALL Script... something missing

Michael-



Thanks for the reply and the links. I see the reason for the initial

error in Const ForAppending. I've read the document and updated to 8.



I already have the WSH 5.6 documentation and I've gone through it. I

also have the Windows 2000 Scripting Guide that I'm going through.

With these and other documention, I am still unable to come up with

the missing line in my script. Any ideas or hints?



Thanks.







On Thu, 20 Nov 2003 17:38:35 -0800, "Michael Harris \(MVP\)"

<mikhar@mvps.org>wrote:



Quote
BS_WTF_123 wrote:

>All-

>

>I am trying to write up a small VBScript that will run the ipconfig

>/all command on a list of servers in a text file and output the

>results to another text file.

>

>I've run into one issue. When I run the script, instead of writing

>all of the ipconfig /all results to the output file, it writes the

>results of the first server only (and it repeats that for however many

>servers I have in the input file).

>

>Here is what I have now:

>

>Const ForAppending = 2





Const ForAppending = 8



OpenTextFile Method

msdn.microsoft.com/library/en-us/script56/html/jsmthopentextfile.asp">msdn.microsoft.com/library/en-us/script56/html/jsmthopentextfile.asp



WSH 5.6 documentation download

http://www.microsoft.com/downloads/details.aspx?FamilyId" rel="nofollow" target="_blank">www.microsoft.com/downloads/details.aspx=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en







>Set objFSO = CreateObject("Scripting.FileSystemObject")

>Set objTextFile = objFSO.OpenTextFile _

>("c:\results.txt", ForAppending, True)

>Const INPUT_FILE_NAME = "C:\servers.txt"

>Const FOR_READING = 1

>Set objFSO = CreateObject("Scripting.FileSystemObject")

>Set objFile =

>

>objFSO.OpenTextFile(INPUT_FILE_NAME,FOR_READING)

>strComputers = objFile.ReadAll

>objFile.Close

>arrComputers = Split(strComputers, vbCrLf)

>For Each strComputer In arrComputers

>Set objShell = CreateObject("WScript.Shell")

>Set objScriptExec = objShell.Exec("ipconfig /all")

>strIpConfig = objScriptExec.StdOut.ReadAll

>For Each ??????????????????????

>objTextFile.WriteLine(strIpConfig)

>Next

>Next

>objTextFile.Close

>

>------------

>

>The line containing "For Each ??????????????????????" is the line

>where I know I'm missing the For Each.. but I can't seem to get it

>right.

>

>Any ideas?

>

>Thanks.



-

Re:IPCONFIG /ALL Script... something missing

BS_WTF_123 wrote:



Quote
I am trying to write up a small VBScript that will run the ipconfig

/all command on a list of servers in a text file and output the

results to another text file.



Hi



I'm not sure what you mean here. As far as I know, you can't run ipconfig.exe

against a remote computer.







--

torgeir

Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of the 1328 page

Scripting Guide: www.microsoft.com/technet/scriptcenter">www.microsoft.com/technet/scriptcenter





-

Re:IPCONFIG /ALL Script... something missing

Torgeir-



Sure you can! I ran it against a remote computer already. It works

well. I found the method on the web somewhere. My issue is trying to

write the output to a output text file. I am missing something. Try

my script (you'll need to create an input file at c:\servers.txt).

Maybe you can offer up some info on what I'm missing.



Thanks!



On Fri, 21 Nov 2003 18:06:31 +0100, "Torgeir Bakken (MVP)"

<Torgeir.Bakken-spam@hydro.com>wrote:



Quote
BS_WTF_123 wrote:



>I am trying to write up a small VBScript that will run the ipconfig

>/all command on a list of servers in a text file and output the

>results to another text file.



Hi



I'm not sure what you mean here. As far as I know, you can't run ipconfig.exe

against a remote computer.



-

Re:IPCONFIG /ALL Script... something missing

BS_WTF_123 wrote:



Quote
Torgeir-



Sure you can! I ran it against a remote computer already. It works

well. I found the method on the web somewhere. My issue is trying to

write the output to a output text file. I am missing something. Try

my script (you'll need to create an input file at c:\servers.txt).

Maybe you can offer up some info on what I'm missing.



Hi



Ok, but I can't se that your line

Set objScriptExec = objShell.Exec("ipconfig /all")

will address a remote computer. Where is the remote computer name?





--

torgeir

Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of the 1328 page Scripting

Guide: www.microsoft.com/technet/scriptcenter">www.microsoft.com/technet/scriptcenter





-

Re:IPCONFIG /ALL Script... something missing

Torgeir-



I am parsing an input file containing a list of remote systems:

For Each strComputer In arrComputers

Set objShell = CreateObject("WScript.Shell")

Set objScriptExec = objShell.Exec("ipconfig /all")



The input file is read here:

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1



My problem is that when I go to output the results, I need a For Each

line ... but I can't figure out what to specify:

For Each ??????????????????????

objTextFile.WriteLine(strIpConfig)

Next

Next

objTextFile.Close



For reference, here is the entire script right this second:

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile _

("c:\results.txt", ForAppending, True)

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME,FOR_READING)

strComputers = objFile.ReadAll

objFile.Close

arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Set objShell = CreateObject("WScript.Shell")

Set objScriptExec = objShell.Exec("ipconfig /all")

strIpConfig = objScriptExec.StdOut.ReadAll

For Each ??????????????????????

objTextFile.WriteLine(strIpConfig)

Next

Next

objTextFile.Close

-------------------------------



Thanks.







On Fri, 21 Nov 2003 18:41:44 +0100, "Torgeir Bakken (MVP)"

<Torgeir.Bakken-spam@hydro.com>wrote:



Quote
BS_WTF_123 wrote:



>Torgeir-

>

>Sure you can! I ran it against a remote computer already. It works

>well. I found the method on the web somewhere. My issue is trying to

>write the output to a output text file. I am missing something. Try

>my script (you'll need to create an input file at c:\servers.txt).

>Maybe you can offer up some info on what I'm missing.



Hi



Ok, but I can't se that your line

Set objScriptExec = objShell.Exec("ipconfig /all")

will address a remote computer. Where is the remote computer name?



-

Re:IPCONFIG /ALL Script... something missing

BS_WTF_123 wrote:



Quote
Torgeir-



I am parsing an input file containing a list of remote systems:

For Each strComputer In arrComputers

Set objShell = CreateObject("WScript.Shell")

Set objScriptExec = objShell.Exec("ipconfig /all")



The input file is read here:

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1



My problem is that when I go to output the results, I need a For Each

line ... but I can't figure out what to specify:

For Each ??????????????????????

objTextFile.WriteLine(strIpConfig)

Next

Next

objTextFile.Close



For reference, here is the entire script right this second:

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile _

("c:\results.txt", ForAppending, True)

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME,FOR_READING)

strComputers = objFile.ReadAll

objFile.Close

arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers



Where and for what do you want to use the strComputer variable?





Quote
Set objShell = CreateObject("WScript.Shell")

Set objScriptExec = objShell.Exec("ipconfig /all")

strIpConfig = objScriptExec.StdOut.ReadAll

For Each ??????????????????????

objTextFile.WriteLine(strIpConfig)

Next

Next



You can use %comspec% redirection instead maybe to create the output file (the

Quote
>will append to an existing file) :





Const OUTPUT_FILE_NAME = "C:\results.txt"

Const INPUT_FILE_NAME = "C:\servers.txt"

Const FOR_READING = 1

Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME,FOR_READING)

strComputers = objFile.ReadAll

objFile.Close



arrComputers = Split(strComputers, vbCrLf)



On Error Resume Next

objFSO.DeleteFile(OUTPUT_FILE_NAME)

On Error Goto 0



For Each strComputer In arrComputers

objShell.Run "%comspec% /c ipconfig.exe /all>>" & OUTPUT_FILE_NAME, 0,True

Next



objShell.Run "notepad.exe " & OUTPUT_FILE_NAME







--

torgeir

Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of the 1328 page

Scripting Guide: www.microsoft.com/technet/scriptcenter">www.microsoft.com/technet/scriptcenter





-