PowerShell - How to modify system iFile?
I use PowerShell to upload a text file containing a number of parameters that I want to use in an existing iRule.
Through the web-gui I have already created an iFile named 'iFileApiKeys'.
In PowerShell I use this procedure to upload the text file:
$length = "0-" + ($fileContent.Length - 1) + "/" + $fileContent.Length
$headers = @{ "Content-Range" = $length}
$uploadResult = Invoke-WebRequest $URL -Method POST -Headers $headers -InFile $filePathPlusTextfile -
ContentType "multipart/form-data" -TimeoutSec 20 -Credential $mycreds | ConvertFrom-Json
Write-Host "Upload Result:"
Write-Host $uploadResult
According to the 'uploadResult' the file ends up in the folder:'var/config/rest/downloads/iFileApiKeys.txt' on my F5 LTM
Using 'SuperPutty' I can via tmos (tmsh) modify the existing system iFile by executing:
`tmos> modify /sys file ifile iFileApiKeys source-path file:///var/config/rest/downloads/iFileApiKeys.txt
My problem is that I can't seem to find the correct PowerShell command to achieve the same result as the tmos (tmsh) command does.
I want to use and actually think I should use:
`Invoke-Webrequest -Method Put`
I've been trying to emulate an example taken from a Jason Rahm post on this site: https://devcentral.f5.com/articles/getting-started-with-icontrol-working-with-the-system-20592
Like this:
$sysIfilePath = "/mgmt/tm/sys/file/ifile/iFileApiKeys"
`$sysPath = "https://" + $host_address + $sysIfilePath
$updateresult = Invoke-WebRequest -Method Put -Uri $sysPath -Headers $headers -Credential $mycreds -Body $body
But this command fails unfortunately,
My assumption is that I don't fill $headers and/or $body with the correct values.
When executing a GET for my sys iFile object the result is:
``{"kind":"tm:sys:file:ifile:ifilestate","name":"iFileApiKeys","fullPath":"iFileApiKeys","generation":10970077,"selfLink":"https://localhost/mgmt/tm/sys/file/ifile/iFileApiKeys?ver=13.1.0.2","chec
ksum":"SHA1:878:52a261b5a113db5c9421a54e1e8b5685e7da7a4d","createTime":"2018-11-26T22:52:08Z","createdBy":"per.eriksson","lastUpdateTime":"2018-12-08T19:49:15Z","mode":33188,"revision":24,"size"
:878,"sourcePath":"file:///var/config/rest/downloads/iFileApiKeys.txt","updatedBy":"per.eriksson"}
Anyone out there that can point me in the right direction on how to update my sys iFile using PowerShell?
Thank you!
/Per