# Remove iRule From Multiple Virtual Servers

**URL:** <https://community.f5.com/t/remove-irule-from-multiple-virtual-servers/64788>\
**Category:** Community CodeShare\
**Tags:** tmsh, irules, devops, application-delivery\
**Created:** [March 10, 2015, 7:11pm UTC](https://community.f5.com/t/remove-irule-from-multiple-virtual-servers/64788 "2015-03-10T19:11:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeCentral\_194](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@CodeCentral\_194](https://community.f5.com/u/CodeCentral_194)\
**Post date:** [March 10, 2015, 7:11pm UTC](https://community.f5.com/t/remove-irule-from-multiple-virtual-servers/64788/1 "2015-03-10T19:11:33Z")

</div>

**Problem this snippet solves:**

Remove an iRule from one or more virtual servers. This script will search through the BIG-IP virtual servers for the specified iRule and remove it from any virtual server (not from the system).

**How to use this snippet:**

### Script output

```auto
# run cli script delrule.tcl filler2
The filler2 iRule was removed from the following virtuals:
  tmshtest2
 tmshtest3
 tmshtest4
 tmshtest5
 tmshtest7
 tmshtest8
 tmshtest9
 tmshtest10

```

**Code :**

```auto
script delrule.tcl {

proc script::run {} {
    if { $tmsh::argc != 2 } {
       puts "A single rule name must be provided"
       exit
   }
   set rulename [lindex $tmsh::argv 1]
   set rules ""
   set vips [tmsh::get_config /ltm virtual]
   set vips_in_play "" 

    tmsh::begin_transaction 

    foreach vip $vips { 
# Rule keyword not present
        if { [tmsh::get_field_value $vip "rules" rules] == 0 } {
           continue
        }
# Rule keyword is present, but not $rulename rule
        if { [lsearch -exact $rules $rulename] == -1 } {
           continue
        }
# If only 1 rule applied, can use the none attribute, otherwise, must
# "pop" $rulename from the rule list and re-apply
        if { [llength $rules] < 2 } {
           tmsh::modify /ltm virtual [tmsh::get_name $vip] rules none
           lappend vips_in_play $vip
       } else {
           set id [lsearch -exact $rules $rulename]
           set keepers [lreplace $rules $id $id]
           tmsh::modify /ltm virtual [tmsh::get_name $vip] rules "{ $keepers }"
           lappend vips_in_play $vip
       }
    }

    tmsh::commit_transaction 

    puts "The $rulename iRule was removed from the following virtuals: "
   foreach x $vips_in_play {
       puts "\t[tmsh::get_name $x]"
    }
}

}

```

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [January 28, 2016, 12:08pm UTC](https://community.f5.com/t/remove-irule-from-multiple-virtual-servers/64788/2 "2016-01-28T12:08:36Z")

</div>

Code Fork /w Multiple Partition Support: [Remove iRule From Multiple Virtual Servers (Fork /w multiple partition support) - Community CodeShare - DevCentral - An F5 Technical Community](https://devcentral.f5.com/s/articles/remove-irule-from-multiple-virtual-servers-fork-w-multiple-partition-support)
