Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology

Trying to add persistence profile in existing virtual server

I am trying to add persistence profile in an existing Virtual server but not able to do so. It is showing some errors.

Add-PSSnapIn iControlSnapIn
Initialize-F5.iControl -Hostname "hostname" -Username "username" -Password "password"

$virtual_name = New-Object iControl.CommonVirtualServerDefinition
$vir_server = New-Object iControl.LocalLBVirtualServerVirtualServerPersistence
$vir_server.default_profile = $false


Error this time is -

Exception calling "add_persistence_profile" with "2" argument(s): "Exception caught in 
Exception: Common::OperationFailed
    primary_error_code   : 16908342 (0x01020036)
    secondary_error_code : 0
    error_string         : 01020036:3: The requested virtual server 
(/Common/iControl.CommonVirtualServerDefinition) was not found."
At line:12 char:1
+ (Get-F5.iControl).LocalLBVirtualServer.add_persistence_profile($virtu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SoapHeaderException

I am making some mistake not sure what exactly is that. Could someone please help me out with this ?

Rate this Question

Answers to this Question


I do not know PowerShell, but from the error message, The requested virtual server (/Common/iControl.CommonVirtualServerDefinition) was not found, I would say that the virtual does not exist. Check if exists.

If that's not the case, I suspect the data format of the persistence profile(s). It must be given in array ([]). For example, to perform the task equivalent to the following tmsh command (adding cookie persistence profile to the virtual vs):

tmsh modify ltm virtual vs persist replace-all-with { cookie }

You need to PATCH the /mgmt/tm/ltm/virtual/vs endpoint with the data {"persist":[ {"name":"cookie"} ]}.

A curl call looks like this:

curl -sku <admin>:<adminPass> https://<host>/mgmt/tm/ltm/virtual/vs \
  -X PATCH -H "Content-type: application/json" \
  -d '{"persist":[ {"name":"cookie"} ]}'
Comments on this Answer
Comment made 2 months ago by Ansh Jain 56

Thanks Satoshi for your response over this issue. You are right. The persistent profile needs to be passed as an array in powershell. I did the same and issue has been resolved, I forgot to mark it. This is working piece.

$Persistence = New-Object -TypeName iControl.LocalLBVirtualServerVirtualServerPersistence; 
$Persistence.profile_name = 'source_addr' 
$Persistence.default_profile = $true 
$Pers_ProfileA = (, $Persistence); 
$Pers_ProfileAofA = (, $Pers_ProfileA); 

Write-Host "Enabling Source Address Affinity on Virtual Server `"$name`"..."; 

(Get-F5.iControl).LocalLBVirtualServer.add_persistence_profile($name, $Pers_ProfileAofA) 

Reference: https://devcentral.f5.com/questions/looking-for-help-with-add_persistence_profile