Forum Discussion
Powershell New-F5Session and close session issues.
Did you try the passthru switch Joel mentioned in the issue I shared? Seems to be the same scenario you mentioned, but posh is not my jam so I'm just throwing ideas out.
Yeah, I am able to get it to work for 1 session but I am not sure how to do 2 sessions since we have 2 F5s that we have to change iRules on. It seems like the New-F5Session is part of the scripts attributes and so the calls to Add-iRuleToVirtualServer assumes the "current F5 session" that is open so passthru might be the default. Joel may know of an alternative so I will have to wait and see.
I can always create another script that handles iRules for the other F5 but it involves a little more work and 2 separate scripts and commands to be created and executed.
- JRahmAug 02, 2022
Admin
Looking through some comments on the codeshare, i found this:
$F5Session = New-F5session -LTMName $host_address -LTMCredentials $mycreds -PassThrough; Get-Pool -F5Session $F5Session | Select-Object -ExpandProperty fullPath;So maybe if you had that in a loop and just passed in $host_address from the iterable it would update? No worries if you've tried this, still slinging mud against the wall in the event something sticks... 🙂
- LanceLyonsAug 04, 2022
Cirrus
Hi Jason,
I have left a post over in this area for Joel but have not heard back https://github.com/joel74/POSH-LTM-Rest/issues/219
I have tried the code below and I still get this error thinking its coming from the Get-VirtualServer calls
You must either create an F5 Session with script scope (by calling New-F5Session with -passthrough parameter) or pass an F5 session to this function.
$session_inside = New-F5Session -LTMName $ltmip_inside -LTMCredentials $mycreds $vipObject_inside = Get-VirtualServer -F5Session $session_inside -Name $vipName $session_external = New-F5Session -LTMName $ltmip -LTMCredentials $mycreds $vipObject_external = Get-VirtualServer -F5Session $session_external -Name $vipName if ($vipName.ToLower() -contains "internal") { $vipObject = $vipObject_inside } else { $vipObject = $vipObject_external } foreach ($viprule in $vipObject.rules) { switch ($action.tolower()) { "add" { switch ($type.tolower()) { "all" { if ($vipName.ToLower() -contains "internal") { $add = Add-iRuleToVirtualServer -F5Session $session_inside -InputObject $vipObject -iRuleName $all_MaintRule } else { $add = Add-iRuleToVirtualServer -F5Session $session_external -InputObject $vipObject -iRuleName $all_MaintRule } $status = "Updated" } "external" { if ($vipName.ToLower() -contains "internal") { $add = Add-iRuleToVirtualServer -F5Session $session_inside -InputObject $vipObject -iRuleName $external_MaintRule } else { $add = Add-iRuleToVirtualServer -F5Session $session_external -InputObject $vipObject -iRuleName $external_MaintRule } $status = "Updated" } default { $status = "Error - rule type not specified" } } } "remove" { if ($vipName.ToLower() -contains "internal") { $remove = Remove-iRuleFromVirtualServer -F5Session $session_inside -InputObject $vipObject -iRuleName $all_MaintRule $remove = Remove-iRuleFromVirtualServer -F5Session $session_inside -InputObject $vipObject -iRuleName $external_MaintRule } else { $remove = Remove-iRuleFromVirtualServer -F5Session $session_external -InputObject $vipObject -iRuleName $all_MaintRule $remove = Remove-iRuleFromVirtualServer -F5Session $session_external -InputObject $vipObject -iRuleName $external_MaintRule } $status = "Updated" } default { $status = "Error - action type not specfied" } } }- LanceLyonsAug 04, 2022
Cirrus
Also tried directly in Powershell session and the same error.
trying to pass the F5 session
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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