#176714 - 2007-06-04 10:17 AM
Problems outputting information to text file....
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
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 - 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 - 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)
|
|
Top
|
|
|
|
#176745 - 2007-06-05 10:20 AM
Re: Problems outputting information to text file....
[Re: Glenn Barnas]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
Awesome! Works a treat. Thanks Glenn! Final code for this anyway is below in case it helps anyone! 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
$RC = RedirectOutput('c:\temp\log.txt')
"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 ?
@CRLF
Next
$RC = RedirectOutput('')
Need to start trying to figure out how to get the output now into a pop up type window....hopefully that is easy to do!
Edited by jules666 (2007-06-05 10:20 AM)
|
|
Top
|
|
|
|
#176746 - 2007-06-05 10:43 AM
Re: Problems outputting information to text file....
[Re: jules666]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
Just noticed, not sure if its obvious fix but in my code above when running on various machines, sometimes an adapter is listed twice...most odd. If anyone has an ideas please let me know!
Glenn - Have come accross a post by you for your NICINFO udf...may have to figure how to use that instead as that looks to be doing what I wanted and more
|
|
Top
|
|
|
|
#176781 - 2007-06-06 03:56 AM
Re: Problems outputting information to text file....
[Re: jules666]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Got hammered with problems at work today.. here's the header code:
Break On
Dim $, $aND[19], $aNicInfo, $N, $P
$=setoption("Wrapateol","on")
$=setoption("Explicit","off")
$=setoption("NoVarsinstrings","on")
$=setoption("NoMacrosinstrings","on")
If Not IsDeclared($TARGET)
Global $TARGET
EndIf
If $TARGET = ''
$Target = @WKSTA
EndIf
$aND[0] = ' Adapter Description: '
$aND[1] = ' Manufacturer: '
$aND[2] = ' NIC GUID: '
$aND[3] = ' Speed/Duplex value: '
$aND[4] = ' Speed/Duplex text: '
$aND[5] = ' Driver Version: '
$aND[6] = ' DHCP boolean (1=Use DHCP): '
$aND[7] = 'IP settings (add,mask,gw): '
$aND[8] = ' Domain Name: '
$aND[9] = ' DNS Server list: '
$aND[10] = ' DHCP Server & Lease info: '
$aND[11] = ' WINS Server list: '
$aND[12] = ' Interface Name: '
$aND[13] = ' Static DNS Server List: '
$aND[14] = ' Reserved for future use: '
$aND[15] = ' NIC Status: '
$aND[16] = ' MAC Address: '
$aND[17] = ' TEAM flag: '
$aND[18] = ' # of adapters in team: '
$aND[19] = ' GUIDs of teamed adapters: '
$aNicInfo = NicInfo($TARGET)
For Each $N in $aNicInfo
For $P = 0 to 19
$aND[$P] $N[$P] ?
Next
?
Next
Just tack the NicInfo UDF to the end of this code and save it as NicInfo.kix. Create a batch file NIC.BAT with the following line in it:
@kix32.exe nicinfo.kix $TARGET="%1"
Run NIC, or NIC COMPUTERNAME to get a list of every network adapter and settings. This header was an example of how to use the UDF and became a useful tool to quickly verify remote network settings.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#176802 - 2007-06-07 10:19 AM
Re: Problems outputting information to text file....
[Re: Glenn Barnas]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
Thanks for that Glenn
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 292 anonymous users online.
|
|
|