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 Figured it out, and I shamelessly stole his code and made it into this shorter snippet.

His larger Reporter Code can be found here

Also for the poor sucker that is trying to find the powershell module snapin - try here - - unblock it at the file explorer level, extract and run it. Then download the github repo for the newer code from here - - 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 = ''
#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 ''
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

Was this article helpful?

No CommentsBe the first to comment