Upload a file as iFile using iControl

409 Views Asked by At

Is there a way to update the contents of an existing iFile? I didn't see any way to update the contents. So, I started looking at deleting and creating a file by uploading a local file to the BigIP using the iControl. I understand there are two objects to use - iFileFile and then iFile in that order.

Can somebody please provide usage for this? Below is what I started with and get the error below. What would be the correct parameters for iFileFile.create() if I have a file named random_key_file1 in the same location as the powershell script? After creating the iFileFile object, how do I use the same in the iFile.create().

Below links have documentation but lack the ussage examples : https://devcentral.f5.com/wiki/iControl.LocalLB__iFile__create.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__iFileFile__create.ashx

Appreciate the help.

Add-PSSnapIn iControlSnapIn

$conn = Initialize-F5.iControl -HostName $hostName -Username $username -Password $password
if($conn) {

    Try
    {
        Write-Output "Connected to load balancer - $hostName"
        $ic = Get-F5.iControl
        $iFileFileObjectNames = @("file1")
        $filePaths = @("random_key_file1")
        $ic.LocalLBiFileFile.create($iFileFileObjectNames,$filePaths)
        Write-Output ("file created")
    }
    Catch
    {
        Write-Output($error[0]|format-list -force)
    }
}   
else
{
    Write-Error "Connection to loadbalancer failed"
}

ERROR

Exception             : System.Management.Automation.MethodInvocationException: Exception calling "create" with "2"
                        argument(s): "Exception caught in LocalLB::urn:iControl:LocalLB/iFileFile::create()
                        Common::InvalidArgument
                        " ---> System.Web.Services.Protocols.SoapHeaderException: Exception caught in
                        LocalLB::urn:iControl:LocalLB/iFileFile::create()
                        Common::InvalidArgument

                           at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
                        message, WebResponse response, Stream responseStream, Boolean asyncCall)
                           at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[]
                        parameters)
                           at CallSite.Target(Closure , CallSite , Object , Object , Object )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
                        funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
                        frame)
                           at
                        System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                        frame)
                           at
                        System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                        frame)
TargetObject          :
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : SoapHeaderException
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, D:\test.ps1: line 35
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails      :
Answer this Question  0
0

There are 0 best solutions below