MikroTik scripting: simple foreach example

The following example uses MikroTik scripting to iterate over all ethernet interfaces and print the name of the interface:

mikrotik-scripting-simple-foreach-example.rsc
foreach v in=[/interface/ethernet find] do={
    :put [/interface/ethernet get $v value-name=name]
}

Example output:

mikrotik_foreach_output.txt
[admin@MySwitch] > foreach v in=[/interface/ethernet find] do={:put [/interface/ethernet get $v value-name=name]}
ether1
sfp-CoreSwitch-Uplink
sfp-sfpplus3
sfp-NAS
sfp-Virtualization
sfp-WAN
sfp-sfpplus4
sfp-sfpplus7
sfp-sfpplus8

 


Check out similar posts by category: MikroTik