Import-QlikApp.ps1

function Import-QlikApp {
    <#
    .SYNOPSIS
    This function ...
 
    .DESCRIPTION
    A bit more description
 
    .PARAMETER FromPipeline
    Shows how to process input from the pipeline, remaining parameters or by named parameter.
 
    .EXAMPLE
    Import-QlikApp 'abc'
 
    Description of the example.
 
    #>


    <# Enable -Confirm and -WhatIf. #>
    [CmdletBinding(SupportsShouldProcess = $true)]
    param(
        [parameter(Mandatory=$true,Position=0)]
    [string]$file,

    [parameter(Position=1)]
    [string]$name,

    [string]$replace,
    [switch]$upload
    )

    begin {
    }

    process {
    If( $name ) {
      $appName = $name
    } Else {
      $appName = $(gci $file).BaseName
    }
    $path = "/qrs/app/{0}?name=$appName"
    If( $replace ) { $path += "&replace=$replace" }
    If( $upload ) {
      $path = $path -f 'upload'
      return Invoke-QlikUpload $path $file
    } else {
      $path = $path -f 'import'
      return Invoke-QlikPost $path $file
    }
  }

    end {
    }
}

if ($loadingModule) {
    Export-ModuleMember -Function 'Import-QlikApp'
}