For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Connect to version 14 and above with Powershell iControl

Problem this snippet solves:

Customer was asking how to connect to version 14 BigIP with PowerShell. They were previously using version 13 and everything worked with this code:

Add-PSSnapin iControlSnapin;

Write-Output "Initializing F5 iControl..."

Initialize-F5.iControl -HostName $bigiphostname -Username $bigipuser -Password $bigippw

But on version 14 it wouldn't connect. After much searching and testing I found that the BigIPReporter guy https://devcentral.f5.com/s/profile/0051T000008u1WRQAY Figured it out, and I shamelessly stole his code and made it into this shorter snippet.


His larger Reporter Code can be found here

https://devcentral.f5.com/s/articles/bigip-report


Also for the poor sucker that is trying to find the powershell module snapin - try here - https://cdn.f5.com/websites/devcentral.f5.com/downloads/f5-icontrol-powershell-snapin-13_1_0.zip - unblock it at the file explorer level, extract and run it. Then download the github repo for the newer code from here - https://github.com/f5devcentral/f5-icontrol-powershell-snapin - saving it into the F5 directory that was created in the previous step. Then run the installation steps that are detailed in the GitHub code.

How to use this snippet:

Create a file called TestConnection.ps1 and copy in the code changing the values for the first three lines to reflect your environment.

Code :

#Change these values
$BigIPUser = 'admin'
$BigIPPW = 'password'
$BigIPName = '192.168.0.245'
 
#Begin Script
$User = $BigIPUser
$Password = $BigIPPW
 
#Create the string that is converted to Base64
 
$Credentials = $User + ":" + $Password
 
#Encode the string to base64
 
$EncodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Credentials))
 
#Add the "Basic prefix"
$BasicAuthValue = "Basic $EncodedCreds"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $BasicAuthValue)
 
#set the connection to TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
 
#Create the body of the post
 
$Body = @{"username" = $User; "password" = $Password; "loginProviderName" = "tmos" }
 
#Convert the body to Json
 
$Body = $Body | ConvertTo-Json
 
$Response  = Invoke-RestMethod -Method "POST" -Headers $headers -Body $Body -Uri "https://$BigIPName/mgmt/shared/authn/login" -ContentType 'application/json'
Write-Output "Auth token:"
Write-Output $Response.token
 
$success = Initialize-F5.iControl -Username 'admin' -Password 'G00fy123' -HostName '192.168.3.103'
Write-Output "Sucessfully innitialized BigIP: $success"
 
$F5 = Get-F5.iControl
$BigIPHostname = $F5.SystemInet.get_hostname()
Write-Output "BigIP Hostname: $BigIPHostname"

Tested this on version:

No Version Found
Published Jun 03, 2019
Version 1.0
No CommentsBe the first to comment