Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################################################################################
- #
- # Start of config section
- #
- ######################################################################################################################################
- #Setup Credentials
- $UserName = ''
- $Password = ''
- #Which BigIP you're going to connect to
- $BigipIP = ""
- ######################################################################################################################################
- #
- # Start of config section
- #
- ######################################################################################################################################
- if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){
- Add-PSSnapIn iControlSnapIn
- }
- #Setup the F5 interface
- $success = Initialize-F5.iControl -HostName $BigipIP -Username $UserName -Password $Password;
- $f5 = Get-F5.iControl
- #Get the partitions
- $f5partitions = $f5.ManagementPartition
- Function Toogle-Pool-Member {
- Param( [string]$Pool = "",
- [string]$Partition = "",
- [array]$Members = @(),
- [string]$State = "",
- [switch]$All = $false
- )
- #Is the State set to something
- if(!($State.tolower() -eq "enable" -or $State.tolower() -eq "disable")){
- Return "Please set state to Enable or Disable"
- }
- #Does the member exist
- if($Members.Count -eq 0 -and $All -eq $false){
- Return "Specify member or set the all flag."
- } elseif($Members.Count -gt 0 -and $All){
- Return "All flag can't be specified if you defined a member."
- }
- #Was a partition specified
- if($Partition -eq ""){
- Return "Please specify a partition"
- }
- #Was a Pool name specified
- if($Pool -eq ""){
- Return "Please specify a pool"
- }
- #Set the active partition
- $f5partitions.set_active_partition($Partition)
- #Add the partition to the pool
- $Pool = "/" + $Partition + "/" + $Pool
- #Check if the pool exists and get a memberlist if it does
- $PoolMembers = $F5.LocalLBPool.get_member_v2($Pool)[0]
- if(!$PoolMembers){
- Return "Pool did not exist."
- }
- if(!$All){
- #The All flag has not been called. Enabling/disabling per member
- $AddressPortList = New-Object -TypeName iControl.CommonAddressPort[] $Members.Length
- #Create a CommonAddressPort list with all members specified in the parameters
- for($i=0; $i-lt $Members.Length; $i++){
- $Address = $Members[$i].Split(":")[0]
- $Port = $Members[$i].Split(":")[1]
- $AddressPortList[$i] = New-Object -TypeName iControl.CommonAddressPort;
- $AddressPortList[$i].address = $Address
- $AddressPortList[$i].port = $Port
- }
- #Check the state specified
- if($State.tolower() -eq "enable"){
- $State = "STATE_ENABLED"
- } else {
- $State = "STATE_DISABLED"
- }
- #Create a list to tie the state to every member specified
- $MemberStateList = New-Object -TypeName iControl.CommonEnabledState[] $Members.Length
- for($i=0; $i-lt $Members.Length; $i++){
- $MemberStateList[$i] = New-Object -TypeName iControl.CommonEnabledState;
- $MemberStateList[$i] = $State
- }
- #Disable/enable the pool members
- $F5.LocalLBPool.set_member_session_enabled_state(
- (,$Pool),
- (,$AddressPortList),
- (,$MemberStateList)
- )
- } else {
- $MemberStateList = New-Object -TypeName iControl.CommonEnabledState[] $PoolMembers.Length
- #Check the state specified
- if($State.tolower() -eq "enable"){
- $State = "STATE_ENABLED"
- } else {
- $State = "STATE_DISABLED"
- }
- #Create a list to tie the state to every member specified
- for($i=0; $i-lt $PoolMembers.Length; $i++){
- $MemberStateList[$i] = New-Object -TypeName iControl.CommonEnabledState;
- $MemberStateList[$i] = $State
- }
- #Disable/enable all pools
- $F5.LocalLBPool.set_member_session_enabled_state(
- (,$Pool),
- (,$PoolMembers),
- (,$MemberStateList)
- )
- }
- }
- #Examples
- #Note that all pool names, partitions etc are case sensitive.
- #
- #Enable Myserver in the pool Test-Pool under partition Common
- #Toogle-Pool-Member -Pool Test-Pool -Partition Common -Members @("Myserver:80") -State Enable
- #Disable all members in the pool Test-Pool under partition Common
- #Toogle-Pool-Member -Pool Test-Pool -Partition Common -All -State Disable
- #Disable Myserver-01 and Myserver-02 in pool testpool under partition MyPartition
- #Toogle-Pool-Member -Pool testpool -Partition MyPartition -Members @("MyServer-01:80", "Myserver-02:80") -State Enable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement