Technical support and scripting issues
Moderators: Dorian (MJT support), JRL
-
Grovkillen
- Automation Wizard
- Posts: 1128
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
-
Contact:
Post
by Grovkillen » Wed Nov 09, 2016 9:52 am
Hi,
I'm creating a script to gather information about
NICs (network adapters) but I fail to create a variable array name using the Separate> command. Is this not possible? (I always end up with %ARRAY_name% as the actual name of the array).
Code: Select all
VBSTART
Function GetNetworkInformation()
On Error Resume Next
strComputer = "."
GetNetworkInformation = ""
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
For Each objItem in colItems
GetNetworkInformation = GetNetworkInformation & "ArpAlwaysSourceRoute: " & objItem.ArpAlwaysSourceRoute _
& ";" & "ArpUseEtherSNAP: " & objItem.ArpUseEtherSNAP _
& ";" & "Caption: " & objItem.Caption _
& ";" & "DatabasePath: " & objItem.DatabasePath _
& ";" & "DeadGWDetectEnabled: " & objItem.DeadGWDetectEnabled _
& ";" & "DefaultIPGateway: " & objItem.DefaultIPGateway _
& ";" & "DefaultTOS: " & objItem.DefaultTOS _
& ";" & "DefaultTTL: " & objItem.DefaultTTL _
& ";" & "Description: " & objItem.Description _
& ";" & "DHCPEnabled: " & objItem.DHCPEnabled _
& ";" & "DHCPLeaseExpires: " & objItem.DHCPLeaseExpires _
& ";" & "DHCPLeaseObtained: " & objItem.DHCPLeaseObtained _
& ";" & "DHCPServer: " & objItem.DHCPServer _
& ";" & "DNSDomain: " & objItem.DNSDomain _
& ";" & "DNSDomainSuffixSearchOrder: " & objItem.DNSDomainSuffixSearchOrder _
& ";" & "DNSEnabledForWINSResolution: " & objItem.DNSEnabledForWINSResolution _
& ";" & "DNSHostName: " & objItem.DNSHostName _
& ";" & "DNSServerSearchOrder: " & objItem.DNSServerSearchOrder _
& ";" & "DomainDNSRegistrationEnabled: " & objItem.DomainDNSRegistrationEnabled _
& ";" & "ForwardBufferMemory: " & objItem.ForwardBufferMemory _
& ";" & "FullDNSRegistrationEnabled: " & objItem.FullDNSRegistrationEnabled _
& ";" & "GatewayCostMetric: " & objItem.GatewayCostMetric _
& ";" & "IGMPLevel: " & objItem.IGMPLevel _
& ";" & "Index: " & objItem.Index _
& ";" & "IPAddress: " & objItem.IPAddress _
& ";" & "IPConnectionMetric: " & objItem.IPConnectionMetric _
& ";" & "IPEnabled: " & objItem.IPEnabled _
& ";" & "IPFilterSecurityEnabled: " & objItem.IPFilterSecurityEnabled _
& ";" & "IPPortSecurityEnabled: " & objItem.IPPortSecurityEnabled _
& ";" & "IPSecPermitIPProtocols: " & objItem.IPSecPermitIPProtocols _
& ";" & "IPSecPermitTCPPorts: " & objItem.IPSecPermitTCPPorts _
& ";" & "IPSecPermitUDPPorts: " & objItem.IPSecPermitUDPPorts _
& ";" & "IPSubnet: " & objItem.IPSubnet _
& ";" & "IPUseZeroBroadcast: " & objItem.IPUseZeroBroadcast _
& ";" & "IPXAddress: " & objItem.IPXAddress _
& ";" & "IPXEnabled: " & objItem.IPXEnabled _
& ";" & "IPXFrameType: " & objItem.IPXFrameType _
& ";" & "IPXMediaType: " & objItem.IPXMediaType _
& ";" & "IPXNetworkNumber: " & objItem.IPXNetworkNumber _
& ";" & "IPXVirtualNetNumber: " & objItem.IPXVirtualNetNumber _
& ";" & "KeepAliveInterval: " & objItem.KeepAliveInterval _
& ";" & "KeepAliveTime: " & objItem.KeepAliveTime _
& ";" & "MACAddress: " & objItem.MACAddress _
& ";" & "MTU: " & objItem.MTU _
& ";" & "NumForwardPackets: " & objItem.NumForwardPackets _
& ";" & "PMTUBHDetectEnabled: " & objItem.PMTUBHDetectEnabled _
& ";" & "PMTUDiscoveryEnabled: " & objItem.PMTUDiscoveryEnabled _
& ";" & "ServiceName: " & objItem.ServiceName _
& ";" & "SettingID: " & objItem.SettingID _
& ";" & "TcpipNetbiosOptions: " & objItem.TcpipNetbiosOptions _
& ";" & "TcpMaxConnectRetransmissions: " & objItem.TcpMaxConnectRetransmissions _
& ";" & "TcpMaxDataRetransmissions: " & objItem.TcpMaxDataRetransmissions _
& ";" & "TcpNumConnections: " & objItem.TcpNumConnections _
& ";" & "TcpUseRFC1122UrgentPointer: " & objItem.TcpUseRFC1122UrgentPointer _
& ";" & "TcpWindowSize: " & objItem.TcpWindowSize _
& ";" & "WINSEnableLMHostsLookup: " & objItem.WINSEnableLMHostsLookup _
& ";" & "WINSHostLookupFile: " & objItem.WINSHostLookupFile _
& ";" & "WINSPrimaryServer: " & objItem.WINSPrimaryServer _
& ";" & "WINSScopeID: " & objItem.WINSScopeID _
& ";" & "WINSSecondaryServer: " & objItem.WINSSecondaryServer & "<ENDLINE>"
Next
End Function
VBEND
VBEval>GetNetworkInformation,GetNetworkInformation_res
Separate>GetNetworkInformation_res,<ENDLINE>,GetNetworkInformation_array
Let>GetNetworkInformation_k=0
Repeat>GetNetworkInformation_k
Let>GetNetworkInformation_k=GetNetworkInformation_k+1
Let>ARRAY_name=NICS(%GetNetworkInformation_k%)
Separate>GetNetworkInformation_array_%GetNetworkInformation_k%,;,%ARRAY_name%
Until>GetNetworkInformation_k=GetNetworkInformation_array_count
I have found that the IP address is always returned as a array (among other variables also returned as array) and more information is
found here>>. I hope to get a working script to return me all the values even if arrays (iterate through them before spitting it out).
-
Djek
- Pro Scripter
- Posts: 148
- Joined: Sat Feb 05, 2005 11:35 pm
- Location: Holland
-
Contact:
Post
by Djek » Wed Nov 09, 2016 3:20 pm
hi Grovkillen,
it's perhaps because about 98 percent of the info is empty ?
i tend to use the command wmic to get hardware info, in your case you can try
wmic nicconfig list brief >c:\folder\name.txt
or better
wmic nicconfig get /format:hform >c:\folder\name.html
MS example:
Code: Select all
let>RP_WAIT=1
let>bestand=c:\beheer\nicinfo.html
DeleteFile>bestand
run>cmd /c wmic.exe nicconfig get /format:hform > %bestand%
ExecuteFile>bestand
The html output generates tags so convert it into a html-array, but in fact it's allready easy to read report.
The html output also shows you that most info is empty
kind regards,
Djek
-
JRL
- Automation Wizard
- Posts: 3524
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Wed Nov 09, 2016 3:36 pm
Though I agree with Djek about using wmic, I'm not sure what you want to accomplish so here is your code putting the VBScript results into NIC(1) and NIC(2) arrays.
Code: Select all
VBSTART
Function GetNetworkInformation()
On Error Resume Next
strComputer = "."
GetNetworkInformation = ""
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
For Each objItem in colItems
GetNetworkInformation = GetNetworkInformation & "ArpAlwaysSourceRoute: " & objItem.ArpAlwaysSourceRoute _
& ";" & "ArpUseEtherSNAP: " & objItem.ArpUseEtherSNAP _
& ";" & "Caption: " & objItem.Caption _
& ";" & "DatabasePath: " & objItem.DatabasePath _
& ";" & "DeadGWDetectEnabled: " & objItem.DeadGWDetectEnabled _
& ";" & "DefaultIPGateway: " & objItem.DefaultIPGateway _
& ";" & "DefaultTOS: " & objItem.DefaultTOS _
& ";" & "DefaultTTL: " & objItem.DefaultTTL _
& ";" & "Description: " & objItem.Description _
& ";" & "DHCPEnabled: " & objItem.DHCPEnabled _
& ";" & "DHCPLeaseExpires: " & objItem.DHCPLeaseExpires _
& ";" & "DHCPLeaseObtained: " & objItem.DHCPLeaseObtained _
& ";" & "DHCPServer: " & objItem.DHCPServer _
& ";" & "DNSDomain: " & objItem.DNSDomain _
& ";" & "DNSDomainSuffixSearchOrder: " & objItem.DNSDomainSuffixSearchOrder _
& ";" & "DNSEnabledForWINSResolution: " & objItem.DNSEnabledForWINSResolution _
& ";" & "DNSHostName: " & objItem.DNSHostName _
& ";" & "DNSServerSearchOrder: " & objItem.DNSServerSearchOrder _
& ";" & "DomainDNSRegistrationEnabled: " & objItem.DomainDNSRegistrationEnabled _
& ";" & "ForwardBufferMemory: " & objItem.ForwardBufferMemory _
& ";" & "FullDNSRegistrationEnabled: " & objItem.FullDNSRegistrationEnabled _
& ";" & "GatewayCostMetric: " & objItem.GatewayCostMetric _
& ";" & "IGMPLevel: " & objItem.IGMPLevel _
& ";" & "Index: " & objItem.Index _
& ";" & "IPAddress: " & objItem.IPAddress _
& ";" & "IPConnectionMetric: " & objItem.IPConnectionMetric _
& ";" & "IPEnabled: " & objItem.IPEnabled _
& ";" & "IPFilterSecurityEnabled: " & objItem.IPFilterSecurityEnabled _
& ";" & "IPPortSecurityEnabled: " & objItem.IPPortSecurityEnabled _
& ";" & "IPSecPermitIPProtocols: " & objItem.IPSecPermitIPProtocols _
& ";" & "IPSecPermitTCPPorts: " & objItem.IPSecPermitTCPPorts _
& ";" & "IPSecPermitUDPPorts: " & objItem.IPSecPermitUDPPorts _
& ";" & "IPSubnet: " & objItem.IPSubnet _
& ";" & "IPUseZeroBroadcast: " & objItem.IPUseZeroBroadcast _
& ";" & "IPXAddress: " & objItem.IPXAddress _
& ";" & "IPXEnabled: " & objItem.IPXEnabled _
& ";" & "IPXFrameType: " & objItem.IPXFrameType _
& ";" & "IPXMediaType: " & objItem.IPXMediaType _
& ";" & "IPXNetworkNumber: " & objItem.IPXNetworkNumber _
& ";" & "IPXVirtualNetNumber: " & objItem.IPXVirtualNetNumber _
& ";" & "KeepAliveInterval: " & objItem.KeepAliveInterval _
& ";" & "KeepAliveTime: " & objItem.KeepAliveTime _
& ";" & "MACAddress: " & objItem.MACAddress _
& ";" & "MTU: " & objItem.MTU _
& ";" & "NumForwardPackets: " & objItem.NumForwardPackets _
& ";" & "PMTUBHDetectEnabled: " & objItem.PMTUBHDetectEnabled _
& ";" & "PMTUDiscoveryEnabled: " & objItem.PMTUDiscoveryEnabled _
& ";" & "ServiceName: " & objItem.ServiceName _
& ";" & "SettingID: " & objItem.SettingID _
& ";" & "TcpipNetbiosOptions: " & objItem.TcpipNetbiosOptions _
& ";" & "TcpMaxConnectRetransmissions: " & objItem.TcpMaxConnectRetransmissions _
& ";" & "TcpMaxDataRetransmissions: " & objItem.TcpMaxDataRetransmissions _
& ";" & "TcpNumConnections: " & objItem.TcpNumConnections _
& ";" & "TcpUseRFC1122UrgentPointer: " & objItem.TcpUseRFC1122UrgentPointer _
& ";" & "TcpWindowSize: " & objItem.TcpWindowSize _
& ";" & "WINSEnableLMHostsLookup: " & objItem.WINSEnableLMHostsLookup _
& ";" & "WINSHostLookupFile: " & objItem.WINSHostLookupFile _
& ";" & "WINSPrimaryServer: " & objItem.WINSPrimaryServer _
& ";" & "WINSScopeID: " & objItem.WINSScopeID _
& ";" & "WINSSecondaryServer: " & objItem.WINSSecondaryServer & "<ENDLINE>"
Next
End Function
VBEND
VBEval>GetNetworkInformation,GetNetworkInformation_res
Separate>GetNetworkInformation_res,<ENDLINE>,GetNetworkInformation_array
Let>GetNetworkInformation_k=0
Repeat>GetNetworkInformation_k
Add>GetNetworkInformation_k,1
Let>value=GetNetworkInformation_array_%GetNetworkInformation_k%
If>value<>
Separate>value,;,Array_Name
Let>kk=0
Repeat>kk
Add>kk,1
Let>NICS(%GetNetworkInformation_k%)_%kk%=Array_Name_%kk%
Until>kk=Array_Name_Count
EndIf
DelArray>Array_Name
Until>GetNetworkInformation_k=GetNetworkInformation_array_count
**BREAKPOINT**
-
Grovkillen
- Automation Wizard
- Posts: 1128
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
-
Contact:
Post
by Grovkillen » Wed Nov 09, 2016 5:21 pm
Great JRL, fixed my problem just perfect!
Regarding Djek, he's right... much better solution but you helped me with the "core issue" and he provided me another way!