Forum Discussion

nlongFOG_264986's avatar
Icon for Nimbostratus rankNimbostratus
Jun 16, 2016

powershell module f5-ltm new-f5session function how do I login to F5

Good afternoon; Relatively new to power shell, I'm trying log to one of our F5 devices using the new-F5session function in the F5-ltm module downloaded from the powershell gallery. Have successfully created a $mycreds variable which contains my user name and password used to login into the F5console, according to help command for New-F5Session I need to generate an F5 session object to be used in querying and modifying the F5 LTM.


Has anyone used the F5-ltm powershell module to logon to an F5 and disabled and re-enabled individual nodes located/associated in specific partitions.


Thank you in advance for any and all inputs




2 Replies

  • Good afternoon, Subsequent to posting my question found the following:


    Comment made 1 month ago by Joel Newton  248


    Hi, it looks like you're close. When you call: New-F5session -LTMName $host_address -LTMCredentials $mycreds -PassThrough you should see your session object written out to the console if you successfully connect. -PassThrough is really only needed if you're going to capture the session in a variable and then pass it to a function. You could try: $F5Session = New-F5session -LTMName $host_address -LTMCredentials $mycreds -PassThrough; Get-Pool -F5Session $F5Session | Select-Object -ExpandProperty fullPath; Let me know if this helps. Thanks.




    Comment made 1 month ago by CRM  0


    Thank you very much for the quick response Joel. I tried the method you recommended and even change the F5 being accessed but I'm still getting the same response or a similar one. PS C:\WINDOWS\system32> $host_address = "F5_IP_Address" $secpasswd = ConvertTo-SecureString "F5_Account_Password" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ("F5_Account", $secpasswd) $F5Session = New-F5session -LTMName $host_address -LTMCredentials $mycreds -PassThrough PS C:\WINDOWS\system32> $F5Session Name BaseURL Credential ---- ------- ---------- F5_IP_Address System.Management.Automation.PSCredential Up to this point no errors displayed; but , once I run the next command, the error shown below is displayed. PS C:\WINDOWS\system32> Get-Pool -F5Session $F5Session | Select-Object -ExpandProperty fullPath ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null. At C:\windows\system32\windowspowershell\v1.0\Modules\F5-LTM\1.3.26\Public\Invoke-RestMethodOverride.ps1:36 char:50 + ... $message = $_.ErrorDetails.Message | ConvertFrom-json | Selec ... + ~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidati NullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromJsonCommand Invoke-RestMethodOverride : " : At C:\windows\system32\windowspowershell\v1.0\Modules\F5-LTM\1.3.26\Public\Get-Pool.ps1:32 char:21 + ... $JSON = Invoke-RestMethodOverride -Method Get -Uri $URI -Credenti ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-RestMethodOverride Finally, the only other information that I can add is that the SSL certificate on the F5 is self-signed and that when look at the content of the variables I can see that the correct values are contained. Once again thanks in advance for time and attention to this matter.


    Joel Newton


    Comment made 1 month ago by Joel Newton  248


    Hi, Thanks for trying that. It seems like, for some reason, the message being returned from the failed login attempt can't be converted from JSON. Are you definitely using v11.6 or higher of the LTM? One way to try and get a little more info about the error message would be to: 1) Open the file F5-LTM\Public\Invoke-RestMethodOverride.ps1 file in a text editor 2) On line 36, add a to comment out the JSON conversion and expanded property selection: $message = $_.ErrorDetails.Message | ConvertFrom-json | Select-Object -expandproperty message 3) Add a new line below line 36 to write out the content of $message: Write-Output $message Maybe that will give us a better idea of what's going on. Thanks.


    We are using v11.5.4 on the LTM, hence after copying the commands contributed by Joel Newton, got the same JSON error. We plan to move to v12.1.x in the future. Is there anyway to get around the json message?


    Thank you for your assistance




  • Thought I would finally try this out, I have an irule to add to all VIPs using HTTPs. Seemed that would be easy and quick. I loaded the module, all went well and pretty slick. I needed to use -passthrough with the session to be able to run:

    Get-VirtualServer | Where-Object {($_.Destination -like "*443*")} | Select-Object Name

    with passthrough in my new-f5session command I was good.

    Then a few minutes later I got this error and do not know how to get around it.

    Invoke-F5RestMethod : "401 F5 Authorization Required: X-F5-Auth-Token does not exist.