14-May-2020 12:18
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.
24-May-2020 18:27
References:
For iControl REST in general:
For PowerShell:
For file (including certs and keys) upload and configurations:
26-May-2020 14:07
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