Forum Discussion

SteveEason's avatar
Jul 12, 2021

Using Powershell to pull pool members from pool during deployment, but want it to continue and time out after a variable time setting

We are currently using a powershell script to move pool members in and out of pools during deployment. We have one site that the connection can sometimes remain open for a long period of time. We'd like to set a limit on how long it will wait for a connection to close before forcing the connection closed no matter how many connections remain open. We are using the code below to disable the F5 pool member.


function Disable-F5PoolMember
		[Parameter(Mandatory = $true)]
		[Parameter(Mandatory = $true)]
		[Parameter(Mandatory = $true)]
		[Parameter(Mandatory = $true)]

	Write-Host "Disabling Member : $member";	
	$formattedPool = Get-F5FormattedName -Name $Pool;
	$formattedMember = Get-F5FormattedName -Name $Member;
	$memberPath = "/mgmt/tm/ltm/pool/$formattedPool/members/$formattedMember"
	$requestBody = @{
		} | ConvertTo-Json;
	Write-Host "Setting Session State to Disabled on $member";

	try {
			$member_state_response = Invoke-F5RestCall -Method Patch -F5Device $Device -Credentials $Credentials -Path $memberPath -Body $requestBody
			$cur_connections = 1;
			while ( $cur_connections -gt 0 )
				Write-Host "Waiting for current connections to drop to zero..."
				$memberStatus = Get-F5PoolMemberStatus -Device $Device -Credentials $Credentials -Pool $Pool -Member $Member;
				$cur_connections = $memberStatus.curConns;
				Write-Host "Current Connections: $cur_connections"
				Start-Sleep -s 5
			Write-Host "`t Session State : $($member_state_response.session)";
			Write-Host "`t Monitor State : $($member_state_response.state)`n";
	catch {
		$_.Exception | Format-List -Force


What I'd like to do is have it wait for a variable amount of time ($timetowait) (or something like that) that can be passed down through the CI/CD pipeline. So then our developers can input how much time, in minutes, they want to wait for the nodes to clear. So for example, if they enter 10 mins, if the pool still has connections after 10 mins, it will stop waiting and close all connections to that node.


I've dug through the documentation but I'm not seeing anything along these lines.


This way the powershell script will complete successfully and won't fail out the CI/CD pipeline process. And then we can continue on with the next steps.


No RepliesBe the first to reply