Hi, i have this code that gets a list of pools, then uses “Get-F5.LTMPoolMember” to get a list of poolmembers. The output looks like this:
Pool : /blablabla_pool
Address : 10.80.15.xxx
Port : 0
Name : 10.80.15.xxx:0
Availability : AVAILABILITY_STATUS_GREEN
Enabled : ENABLED_STATUS_ENABLED
Status : Pool member is available
Pool : /blablabla2_pool
Address : 10.80.7.xxx
Port : 0
Name : 10.80.7.xxx:0
Availability : AVAILABILITY_STATUS_GREEN
Enabled : ENABLED_STATUS_ENABLED
Status : Pool member is available
My problem is that it takes almost 1,5 minute to generate the list, so i’m guessing that there’s something wrong with my code. That part of the code looks like this:
function Get-Pools()
{
(Get-F5.iControl).LocalLBPool.get_list();
}
----------------------------------------------------------------------------
$pools = Get-Pools
$poolmembers = foreach($pool in $pools) { Get-F5.LTMPoolMember -Pool $pool }
$poolmembers
Would appreciate some help!
Hi Conny!
You can actually fetch an array of pools at the same time which reduces overhead alot.
Something like this:
if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){
Add-PSSnapIn iControlSnapIn
}
$user = 'myuser'
$pass = 'mypassword'
$success = Initialize-F5.iControl -Username $user -Password $pass -HostName 1.1.1.1
$f5 = Get-F5.iControl
$PoolList = $f5.LocalLBPool.get_list()
$ActionServiceDown = $f5.LocalLBPool.get_action_on_service_down($PoolList)
$LBMethod = $f5.LocalLBPool.get_lb_method($PoolList)
for($i=0;$i -lt ($PoolList.Count);$i++){
Pool Name
$PoolList[$i]
Action on service down
$ActionServiceDown[$i]
Load balancing method
$LBMethod[$i]
}
/Patrik
Hi, Thanks! Sorry for the late reply. I can see that your code runs faster, but i don’t know how to use it to get the same output as i get with $poolmembers = foreach($pool in $pools) { Get-F5.LTMPoolMember -Pool $pool }
In many of the examples they use 2D-arrays. Is that the only way to do it? Because that is to advanced for me 
Are you using some kind of framework or custom functions? I am not sure that “Get-F5.LTMPoolMember -Pool $pool” actually exists as a command.
What exactly do you want to do?
/Patrik
Hi, this is complete code:
Add-pssnapin iControlSnapIn
Initialize-F5.iControl -HostName myhost -Username myuser -Password mypass
$ic = Get-F5.iControl
$ic.ManagementPartition.set_active_partition('mypartition')
$pools = Get-F5.LTMPool | Select -ExpandProperty Name
$poolmembers = foreach($pool in $pools) { Get-F5.LTMPoolMember -Pool $pool }
$poolmembers | Where-Object {$_.Availability -eq 'AVAILABILITY_STATUS_RED' }
Hi!
To be honest I did not know that this method existed and I could not find it in the API. However, if all you want is to speed it up I replicated the result in a function below.
Untested on v10 though. Let me know if you encounter issues.
Initialize Snapin
if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){
Add-PSSnapIn iControlSnapIn
}
Add a custom class with properties matching the object you got before
Add-Type @'
public class Member
{
public string Pool;
public string Address;
public string Port;
public string Name;
public string Availability;
public string Enabled;
public string Status;
}
'@
Function Get-Pool-Members {
Param([string]$BigIP, [string]$User, [string]$Password, [string]$Partition="Common")
Declare variables
$ObjMembers = @()
$NodeDict = @{}
Connect to the BigIP
$Success = Initialize-F5.iControl -HostName $BigIP -Username $User -Password $Password
Get an iControl Handle
$F5 = Get-F5.iControl
Change Partition
$F5.ManagementPartition.set_active_partition($Partition)
Get Pool Lists, statuses, nodes etc
$PoolList = $f5.LocalLBPool.get_list()
$Poolmembers = $f5.LocalLBPool.get_member_v2($PoolList)
$PoolMemberstatuses = $F5.LocalLBPool.get_member_object_status($PoolList, $Poolmembers)
$NodeList = $F5.LocalLBNodeAddressV2.get_list()
$NodeIPList = $f5.LocalLBNodeAddressV2.get_address($NodeList)
Save the nodes in a dictionary for convenient access
for($i=0;$i -lt ($NodeList.Count);$i++){
$NodeDict.Add($NodeList[$i], $NodeIPList[$i])
}
for($i=0;$i -lt ($PoolList.Count);$i++){
for($x=0;$x -lt ($PoolMembers[$i].Count);$x++){
Create a new temporary object of the member class
$objTempMember = New-Object Member
Populate the object
$objTempMember.Pool = $PoolList[$i]
$objTempMember.name = $PoolMembers[$i][$x].address
$objTempMember.Address = $NodeDict[$objTempMember.name]
$objTempMember.Port = $PoolMembers[$i][$x].port
$objTempMember.Availability = $PoolMemberstatuses[$i][$x].availability_status
$objTempMember.Enabled = $PoolMemberstatuses[$i][$x].enabled_status
$objTempMember.Status = $PoolMemberstatuses[$i][$x].status_description
Add the object to a list
$ObjMembers += $objTempMember
}
}
Return the object list
Return $ObjMembers
}
$poolmembers = Get-Pool-Members -BigIP "10.0.0.1" -User "myuser" -Password "mypassword" -Partition "Common"
$poolmembers | Where-Object {$_.Availability -eq 'AVAILABILITY_STATUS_RED' }
/Patrik
Hi Patrik, That’s awesome. Thanks!! Really appreciate this.
Inga problem! Let me know if you run into any issues.
/Patrik