Functions/Set-F5Node.psm1
function Set-F5Node { param( [string]$Name, [switch]$Web, [switch]$Endeca, [switch]$Up, [switch]$Down ) if($Up -and $Down){ write-host -foregroundcolor yellow "Specify either Up or Down, not both" return } if($(Get-F5Status -ErrorAction SilentlyContinue) -ne "ACTIVE"){ write-host "Not connected to F5" if(!$(Connect-F5)){ write-host -foregroundcolor red "Unable to find active F5" return } } $EwayPools = @("eway_http_http2","eway_https_http2") $EndecaPools = @("endeca_pool") $Pools = @() if($Web){ $Pools += $EwayPools } if($Endeca){ $Pools += $EndecaPools } if(!$Web -and !$Endeca){ $Pools += $EndecaPools + $EwayPools } $Pools | %{ $PoolName = $_ $MemberName = "" write-host -foregroundcolor white "`nPool: $PoolName" Get-PoolMember -PoolName $PoolName | %{ if($_.name -like "*$($Name)*"){ $MemberName = $_.name write-host -nonewline "`tCurrent status for $MemberName : " if($_.state -eq 'up'){ write-host -nonewline -foregroundcolor green $($_.state) } else { write-host -nonewline -foregroundcolor red $($_.state) } $curconns = (Get-PoolMemberStats -PoolName $PoolName -Name $MemberName)."serverside.curConns".value write-host " ($curconns connections)" } } if($MemberName -eq ""){ write-host -foregroundcolor yellow "`tNo match for '$Name'" } else { if($Up){ if($(read-host "`tENABLE $MemberName ? (y/n) ") -eq "y"){ write-host -nonewline "`tEnabling $MemberName..." $output = Enable-PoolMember -PoolName $PoolName -Name $MemberName sleep 2 write-host -foregroundcolor green "OK" } } elseif($Down){ if($(read-host "`tDISABLE $MemberName ? (y/n) ") -eq "y"){ write-host -nonewline "`tDisabling $MemberName..." $output = Disable-PoolMember -PoolName $PoolName -Name $MemberName -Force sleep 2 write-host -foregroundcolor green "OK" } } if($Up -or $Down){ write-host -nonewline "`tNew status for $MemberName : " $newstate = $((Get-PoolMember -Name $MemberName -PoolName $PoolName).state) if($newstate -eq 'up'){ write-host -foregroundcolor green $newstate } else { write-host -foregroundcolor red $newstate } } } } } function Connect-F5 { $CredFile = "c:\scripts\riojo001-cred.xml" $F5Names = @('10.96.15.150','10.96.15.151') if(!$(Test-Path $CredFile)){ $Cred = Get-Credential } write-host -nonewline "Import Creds..." $Cred = Import-CliXml -Path $CredFile write-host -foregroundcolor green "OK" $F5Names | %{ write-host -nonewline "Creating session on F5 $_..." New-F5Session -LTMName $_ -LTMCredentials $Cred -Default $F5Status = Get-F5Status if($F5Status -eq 'ACTIVE'){ write-host -foregroundcolor green $F5Status return $true } else { write-host -foregroundcolor yellow $F5Status } } return $false } |