Hi I have the following bit of code that returns network adpater information fine in command window but I am trying to output to a txt file.

(Eventually want it to pop up in window when run but figured I would try get the output to a txt file first!)
Main code is -
 Code:
Break On

$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1",,48)
For each $objItem in $colItems

  "Adapter Name: " + $objItem.Description ?

  For each $Item in $objItem.IPAddress
    "IPAddress: " + $Item ?
  Next
    For each $Item in $objItem.DefaultIPGateway
    "DefaultIPGateway: " + $Item ?
  Next

  For each $Item in $objItem.DNSServerSearchOrder
    "DNS Servers: " + $Item ?
  Next
  For each $Item in $objItem.IPSubnet
    "IPSubnet: " + $Item ?
     "MACAddress: " + $objItem.MACAddress ?

  "WINSPrimaryServer: " + $objItem.WINSPrimaryServer ?

  "WINSSecondaryServer: " + $objItem.WINSSecondaryServer ?


Problem is though the I have changed the above code to what is below in the attempt to get it out to a txt file but I do not get the full results only the first adapter.
Code is -
 Code:
Break On
   del c:\temp\log.txt
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1",,48)

For each $objItem in $colItems
 if open(3 , "c:\temp\log.txt" , 5 ) = 0
 writeline ( 3 , "Adapter Name: " + $objItem.Description + @CRLF )

  For each $Item in $objItem.IPAddress
   writeline ( 3 , "IPAddress: " + $Item + @CRLF )
  Next
   For each $Item in $objItem.DefaultIPGateway
 writeline ( 3 , "DefaultIPGateway: " + $Item + @CRLF )
  Next

  For each $Item in $objItem.DNSServerSearchOrder
  writeline ( 3 ,  "DNS Servers: " + $Item + @CRLF )
  Next
  For each $Item in $objItem.IPSubnet
writeline ( 3 ,  "IPSubnet: " + $Item + @CRLF )
  writeline ( 3 ,  "MACAddress: " + $objItem.MACAddress + @CRLF )

  writeline ( 3 ,"WINSPrimaryServer: " + $objItem.WINSPrimaryServer + @CRLF )

 writeline ( 3 , "WINSSecondaryServer: " + $objItem.WINSSecondaryServer + @CRLF )
 endif


sure you experts can see what I am doing wrong, if you could point me in the right direction that would be great!

Thanks in advance \:\)


Edited by jules666 (2007-06-04 11:11 AM)