Forum Discussion
LanceLyons
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"
}
}
}
LanceLyons
Aug 04, 2022Cirrus
Also tried directly in Powershell session and the same error.
- LanceLyonsAug 04, 2022Cirrus
Hi Jason,
I was able to get this going with the session variable. It looks like if you want to use a session variable for the F5 session then you do have to use -PassThrough$F5Session = New-F5Session -LTMName $ltmip_inside -LTMCredentials $mycreds -PassThrough$vipObject = Get-VirtualServer -F5Session $F5Session -Name $vipName$add = Add-iRuleToVirtualServer -F5Session $F5Session -InputObject $vipObject -iRuleName $all_MaintRuleThanks for being persistent with that message. - JRahmAug 09, 2022Admin
glad it worked out! Like I said, I'm throwing mud at the wall and hoped something stuck. Need to re-engage with posh, it's been years and I wasn't that strong when I was writing it.