Forum Discussion
Automation with iControl to upload SSL Cert & Key
I'm trying to create a script via powershell to automate and upload .crt and .key files to our BIG IP environment. I know there are ways to do it via powershell, Just need a place to start. Please help.
- Satoshi_Toyosa1Ret. Employee
References:
For iControl REST in general:
- iControlREST Home. Take a look at one of the PDF documents found in the bottom of the page.
For PowerShell:
For file (including certs and keys) upload and configurations:
- K12522815: Modifying the BIG-IP device SSL certificate configuration using the iControl REST API
- Upload SSL keys/certs via iControl REST API?
- Demystifying iControl REST Part 5: Transferring Files
- JoshBarrow
Cirrus
Found out what I could use. It is actually pretty helpful for folks using Powershell to leverage REST. Thanks to some old buddies of mine. Hopefully this can help someone else as well.
$bigip = Read-Host "BigIP Name: " #Name you would put inside the Web Browser
#Calculate content-range
$standalonefile = Read-Host "Full Filename Inside: "
$pathtofile = "path for the file" + $standalonefile
$file = [IO.File]::ReadAllBytes($pathtofile)
$enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
$encodedfile = $enc.GetString($file)
$range = "0-" + ($encodedfile.Length - 1) + "/" + $encodedfile.Length
$headers = @{ "Content-Range" = $range}
#Upload the file
$filename = Read-Host "Enter Name for inside the BigIP Temp Folder: " #This will be the name of the file inside the bigIP Temp Folder
$url = "https://" + $bigip + "/mgmt/shared/file-transfer/uploads/" + $filename
$credentials = Get-Credential
pause
$uploadresult = Invoke-WebRequest $url -Credential $credentials -method Post -Headers $headers -InFile $pathtofile -ContentType "multipart/form-data" -TimeoutSec 20 | ConvertFrom-Json
#Add new certificate
class cert
{
[string]$command
[string]$name
[string]$fromLocalFile
}
$cert = New-Object -TypeName cert
$cert.command = "install"
$cert.name = Read-Host "Enter Name for inside the BigIP Cert Store:" #this is what will show up inside the cert store. in the F5
$cert.fromLocalFile = $uploadresult.localFilePath
$body = $cert | ConvertTo-Json
$url = "https://" + $bigip + "/mgmt/tm/sys/crypto/cert"
$certresult = Invoke-WebRequest $url -Credential $credentials -method Post -Body $body -ContentType "application/json" -Headers $headers2 | ConvertFrom-Json
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com