Import-QlikContent.ps1

function Import-QlikContent {
    <#
    .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-QlikContent 'abc'
 
    Description of the example.
 
    #>


    <# Enable -Confirm and -WhatIf. #>
    [CmdletBinding(SupportsShouldProcess = $true)]
    param(
            [parameter(Mandatory=$true)]
    [string] $MachineName,
    [parameter(Mandatory=$false)]
    [String]$ContentLibrary="Default",    
    [parameter(Mandatory=$false)]
    [string] $ArtifactPath  = 'C:\Migrate\content-library-upload',    
    [parameter(Mandatory=$false)]
    [System.Management.Automation.PSCredential] $mycreds
    )

    begin {
    }

    process {
        
        $session = New-PSSession -ComputerName $MachineName -Credential $mycreds

        Invoke-Command -Session $session -ScriptBlock{
            param($artifactPath, $contentLibrary)
        #Trust All Certs
        gci 'C:\Program Files\WindowsPowerShell\Modules'  -Recurse | Unblock-File
add-type @'
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
'@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
Connect-Qlik
        
$files = gci $artifactPath
Foreach ($file in $files){
$Path = "/qrs/contentlibrary/$($ContentLibrary)/uploadfile?externalpath=/$($file.Name)&overwrite=true"
    return Invoke-QlikUpload -Path $Path  -filename $files.FullName  #-FilePath $file.FullName


}

                }    -Args ($ArtifactPath, $ContentLibrary)
        }

    end {
    }
}

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