Functions/Set-F5Node.psm1

function Set-F5Node {

    param(
        [Parameter(Mandatory = $false,ValueFromPipeline = $true)]
        [string]$Name,
        [switch]$Web,
        [switch]$Endeca,
        [switch]$Up,
        [switch]$Down,
        [switch]$Sync
    )

    if($Up -and $Down){
        write-host -foregroundcolor yellow "Specify either Up or Down, not both"
        return
    }

    $Session = Connect-F5

    $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 -F5Session $Session| %{
            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 -F5Session $Session)."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 -F5Session $Session
                    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 -F5Session $Session
                    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 -F5Session $Session).state)
                if($newstate -eq 'up'){
                    write-host -foregroundcolor green $newstate
                } else {
                    write-host -foregroundcolor red $newstate
                }
            }
        }
    }

    if($Sync){
        if($(Get-F5Status) -eq 'ACTIVE'){
            write-host -nonewline -foregroundcolor magenta "`nSyncing device to group..."
            $output = Sync-DeviceToGroup -GroupName syncgroup -F5Session $Session
            if($output -eq 'True'){
                write-host -foregroundcolor green "OK"
            } else {
                write-host -foregroundcolor red "FAIL"
            }
        }
        
    }

}