I'm trying to build a config script that will match against any interfaces that are on access VLAN X and change them to access VLAN Y.
I am using the packaged Change VLAN Membership script but I need to add an if/then that looks at the current vlan membership of a port and if it matches X change it to Y.
How do I get at and use the current vlan membership for something like this?
if (@currentVlan == @VlansToRemove)
Currently it looks like this but it never matches:
/*
.CHANGE_TEMPLATE_DESCRIPTION
This change template configures VLAN membership on Cisco IOS devices. The template was verified on Cisco 2950 Catalyst Switch running IOS software version 12.1(12c).
.CHANGE_TEMPLATE_TAGS
Cisco, IOS, VLAN Membership
.PLATFORM_DESCRIPTION
Cisco IOS
.PARAMETER_LABEL @ContextNode
NCM Node
.PARAMETER_DESCRIPTION @ContextNode
The node the template will operate on. All templates require this by default. The target node is selected during the first part of the wizard so it will not be available for selection when defining values of variables.
.PARAMETER_LABEL @TargetPorts
Select Port(s)
.PARAMETER_DESCRIPTION @TargetPorts
Select the port(s) for which you would like to change VLAN membership.
.PARAMETER_LABEL @VlansToRemove
VLAN(s) to remove
.PARAMETER_DESCRIPTION @VlansToRemove
Select the VLAN(s) you would like to remove. Selecting VLANs irrelevant to interfaces simply will result in no actions taken for those interfaces.
.PARAMETER_LABEL @VlanToAssign
VLAN to assign
.PARAMETER_DESCRIPTION @VlanToAssign
Select the VLAN you would like to assign.
*/
script ConfigureVLANmembershipCiscoIOS (
NCM.Nodes @ContextNode,
NCM.Interfaces[] @TargetPorts,
NCM.VLANs[] @VlansToRemove,
NCM.VLANs @VlanToAssign )
{
// Enter configuration mode
CLI
{
configure terminal
}
// Loop through selected ports
foreach (@portItem in @TargetPorts)
{
if (@vlanRemove.VLANID == @VlansToRemove)
{
CLI
{
interface @portItem.InterfaceDescription
}
// Loop through list of vlans to remove
foreach (@vlanRemove in @VlansToRemove)
{
CLI
{
no switchport access vlan @vlanRemove.VLANID
}
}
CLI
{
switchport access vlan @VlanToAssign.VLANID
}
CLI
{
exit
}
}
}
// Exit configuration mode
CLI
{
exit
}
}