cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 7

cisco cli script with 2 loop variables

Is it possible to do a script that outputs 2 looped variables with the below

i input 10,20 and data,voice and get

vlan 10

 name data

vlan 20

 name voice

 

The closest i have been able to come is the below

 

script ConfigureVLANCisco (  

 

                                          NCM.Nodes @ContextNode,

 

                                          string [] @vlans,

 

                                          string [] @vlansname )

 

{

 

  CLI

 

  {

 

   configure terminal

 

  }

 

  foreach (@vlan in @vlans)

  foreach (@name in @vlansname)

  {

 

    CLI

 

    {

 

       vlan @vlan

 

         name @name

    }

 

   }

 

  }

 

 

which outputs

 

vlan 10

 name data

 name voice

vlan 20

 name data

 name voice

 

any help is appreciated.

 

 
 
 
 
 
 
 
0 Kudos
2 Replies
Level 8

Hi

 

If your VLAN IDs and names are static, just do:

 

script ConfigureVLANCisco (  

                                          NCM.Nodes @ContextNode

{

  CLI

  {

   configure terminal

  vlan 10

   name Data

   vlan 20

   name Voice

  }

}

 

 

If you want to be able modify VLAN ID and name, do this: 

 

.PARAMETER_LABEL @VLANid
VLAN ID
.PARAMETER_DESCRIPTION @VLANid
What is the ID of the VLAN being created?.

.PARAMETER_LABEL @VLANname
VLAN Name
.PARAMETER_DESCRIPTION @VLANname
What is the name of the VLAN being created?.


*/

script UpdateTimeZoneCiscoIOS (
NCM.Nodes @ContextNode,
int[] @VLANid,
string @VLANname
) {

CLI {

configure terminal
vlan @VLANid
name @VLANname

}
}

 

 

0 Kudos
Level 7

neither variable is static, i need both variables to be whatever the user inputs.  Also without a foreach loop in your script the variables just spit out

System.Collections.Generic.List`1[System.String]

 

so i updated the script to the below

 

/*

.PARAMETER_LABEL @VLANid
VLAN ID
PARAMETER_DESCRIPTION @VLANid
What is the ID of the VLAN being created?

.PARAMETER_LABEL @VLANname
VLAN Name
PARAMETER_DESCRIPTION @VLANname
What is the name of the VLAN being created?


*/

script CiscoIOS (
NCM.Nodes @ContextNode,
int[] @VLANid,
string[] @VLANname
) {
{
CLI
{
configure terminal
}
}
{

foreach (@vlan in @VLANid)
foreach (@name in @VLANname)

CLI {

configure terminal
vlan @vlan
name @name

}
}
}

 

 

and now the result is the below which is still not what i am looking for

 

configure terminal

vlan 10

  name data

vlan 10

  name voice

vlan 20

  name data

vlan 20

  name voice

 

again i want the user to input multiple items for 2 variables to output the below (input example is 10,20 and data,voice but these are not static can be any number and any string)

 

vlan 10

 name data

vlan 20

 name voice

0 Kudos