Forum Discussion
Powershell Pool creation only adding 1 node
Hoping someone can help me out with some powershell sytax for creating F5 Pools This is what I have, it is part of a deployment script that builds 50+ servers. This is what I was able to piece together from other stuff I found on the internet and here on Devcentral.
$PoolMembers = $Servers | ?{$_.F5Pool -eq $Pool.Name} this populates the $PoolMembers array with 2 servers
$PoolName = $Input + $Pool.Name + "_Pool" Sets pool name
$Members = @()
$LBMethod = "LB_METHOD_LEAST_CONNECTION_MEMBER"
$MonitorName = "https"
ForEach($Node in $PoolMembers)
{
$MemberName = $QAInput + $Node.Name
$MemberPort = 443
$nodeParamsExpected = "$membername`:$memberport"
$MemberDef = New-Object -TypeName iControl.CommonAddressPort
$MemberDef.address = $membername
$MemberDef.port = $memberport
$MemberDefAofA = New-Object -TypeName "iControl.CommonAddressPort[][]" 1,1
$MemberDefAofA[0][0] = $MemberDef
$Members += $MemberDefAofA
}
(Get-F5.iControl).LocalLBPool.Create_v2($PoolName, $LBMethod, $Members)
So, the above code works, but the pool ends up with only 1 member, whichever one is listed first in the array. The $Members variable does have 2 rows it it.
Any thoughts? Help? This should be a pool of 2, not 1
2 Replies
Hi
Seems like you've got some mixup with the array dimensions:
$MemberDefAofA[0][0] = $MemberDef
Adding it to an array
$Members += $MemberDefAofA
would create a tri-dimensional array, I guess.
Try something like this (had to rewrite it since I did not know how you declared the previous variables in your script):
Initialize Snapin if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){ Add-PSSnapIn iControlSnapIn } $User = "iUser" $Password = "mypassword" $Partition = "Common" $BigIP = "192.168.161.10" 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 $PoolMembers = ("192.168.20.1", "192.168.20.2") $PoolName = "PSPool" $Members = @() $LBMethod = "LB_METHOD_LEAST_CONNECTION_MEMBER" $MonitorName = "https" $MemberDefAofA = New-Object -TypeName "iControl.CommonAddressPort[]" 2 $MemberDef = New-Object -TypeName iControl.CommonAddressPort $MemberDef.address = "PajoIIS" $MemberDef.port = 8011 $MemberDefAofA[0] = $MemberDef $MemberDef = New-Object -TypeName iControl.CommonAddressPort $MemberDef.address = "PajoIIS" $MemberDef.port = 8012 $MemberDefAofA[1] = $MemberDef (Get-F5.iControl).LocalLBPool.Create_v2((,$PoolName), (,$LBMethod), (,$MemberDefAofA))
Just a comment. The create_v2 method would technically expect the pool name and load balancing methods to be arrays too. It accepts it, but it's... "prettier" to it that way. 🙂
/Patrik
Did it work for you Jeff?
/Patrik
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com