Hi, our company wants to automate BIG-IP using PowerShell or any windows scripting language. It will be one of those scripts that will be executed in an attempt to automate the server maintenance tasks. Most of our servers are Server 2012 R2 using Powershell v4. Please advise on how we can achieve this. I know there are articles here in PowerShell integration but it doesn’t seem to be updated.
Hi,
Please check out the PowerShell module that I and others developed for scripting the Big-IP LTM. It’s available here: GitHub - joel74/POSH-LTM-Rest: PowerShell module and scripts for working with F5's LTM REST API · GitHub
Out of curiosity, which articles on PS integration did you find that were outdated?
Thanks, Joel
Hi Joel,
Thanks for the response. I’m trying the script but unfortunately I can’t make it work. I’m still new to F5 Big-IP so I’m not sure if I’m passing the right values.
I followed the readme file but I think I’m passing the wrong value in $MyLTM_IP New-F5Session -LTMName $MyLTM_IP -LTMCredentials $mycreds -PassThrough
The website of our BIG-IP is https://[IP]/xui/ and I’m passing the [IP] to $MyLTM_IP
Am I doing it right?
Hi, Jonats, It sounds like you’re doing it right. Are you getting any response / error back? Cheers, Joel
There is no error in creating a session. Right after the New-F5Session command, it says that base URL is https://[IP]/mgmt/tm/ltm which is different to our f5 website (https://[IP]/xui/)
Then I try Get-Pool [pool name] and get the error below. A window will also pop-up for credentials so I guess it wasn’t able to get the session eventhough I use -PassThrough
Test-F5Session : You must either create an F5 Session with script scope (by calling New-F5Session) or pass an F5 session At C:\PowerShell\Modules\F5-LTM\Public\Get-Pool.ps1:25 char:9 + Test-F5Session($F5Session) + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (
[Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-F5Session
ConvertFrom-Json : Cannot bind argument to parameter ‘InputObject’ because it is null. At C:\PowerShell\Modules\F5-LTM\Public\Invoke-RestMethodOverride.ps1:36 char:50 + $message = $_.ErrorDetails.Message | ConvertFrom-json | Select-Objec … + ~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (
[ConvertFrom-Json], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromJs
Invoke-RestMethodOverride : " : At C:\PowerShell\Modules\F5-LTM\Public\Get-Pool.ps1:32 char:21 + $JSON = Invoke-RestMethodOverride -Method Get -Uri $URI -Credential … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (
[Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-RestMethodOverride
Hi, Jonats,
Thanks - I believe that helps clarify things. The URL for using the REST API should be different than the management URL you hit in the browser, so that’s fine.
When you create a new LTM session, you either have the option of setting it as the default session and then you don’t have to pass it to functions (accomplished by using the -Default switch on New-F5Session) or you can store the object passed back by New-F5Session and pass it as a param to the functions like Get-Pool. Try adding -Default to your New-F5Session call and see if that fixes the issue for you.
Thanks, Joel
The iControl PowerShell snapin is F5’s supported and actively maintained for each BIG-IP release with the latest being BIG-IP version 12.1. Download can be available at: https://devcentral.f5.com/d/microsoft-powershell-with-icontrol
I have written quite a few tech tips and code samples on using the PowerShell snapin. Check out the PowerShell page on the https://devcentral.f5.com/wiki/iControl.PowerShell.ashx
There are a few cmdlet’s I wrote for specific use cases, but for the most part, I would suggest focusing on the Get-F5.iControl cmdlet which returns an interface object for all of the iControl SOAP APIs documented here: https://devcentral.f5.com/wiki/iControl.APIReference.ashx
Glad to answer any specific questions you have with regards to using this snapin.
-Joe