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 | %{ $Pool = $_ $Member = "" write-host -foregroundcolor white "`nPool: $Pool" Get-PoolMember -PoolName $Pool | %{ if($_.name -like "*$($Name)*"){ $Member = $_.name write-host -nonewline "`tCurrent status for $Member : " if($_.state -eq 'up'){ write-host -foregroundcolor green $($_.state) } else { write-host -foregroundcolor red $($_.state) } } } if($Member -eq ""){ write-host -foregroundcolor yellow "`tCannot find Pool Member" } if($Up){ if($(read-host "`tENABLE $Member ? (y/n) ") -eq "y"){ write-host -nonewline "`tEnabling $Member..." $output = Enable-PoolMember -PoolName $Pool -Name $Member sleep 2 write-host -foregroundcolor green "OK" } } elseif($Down){ if($(read-host "`tDISABLE $Member ? (y/n) ") -eq "y"){ write-host -nonewline "`tDisabling $Member..." $output = Disable-PoolMember -PoolName $Pool -Name $Member -Force sleep 2 write-host -foregroundcolor green "OK" } } if($Up -or $Down){ write-host -nonewline "`tNew status for $Member : " $newstate = $((Get-PoolMember -Name $Member -PoolName $Pool).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 } |