Deploy-QlikRules.ps1

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


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

    begin {
    }

    process {

#$secpasswd = ConvertTo-SecureString “P@ssword123” -AsPlainText -Force
#$mycreds = New-Object System.Management.Automation.PSCredential (“.\qlikuser”, $secpasswd)

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

        Invoke-Command -Session $session -ScriptBlock{
            param($Artifact)
            gci 'C:\Program Files\WindowsPowerShell\Modules'  -Recurse | Unblock-File
        #Trust All Certs
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
            $rules = gci $Artifact
                            Foreach ($ruleJson in $rules){
                        
                                 $rule  = Get-Content $ruleJson.FullName | ConvertFrom-Json 
                                    Get-QlikRule | ?{$_.Name -eq  $rule.Name } | Remove-QlikRule 

                                # $rule
                               New-QlikRule -category Security  -rulecontext both -name $rule.name -rule $rule.rule -actions $rule.actions  -resourceFilter $rule.resourceFilter #-disabled $false

                            }

                }    -Args ($ArtifactPath)
        }

    end {
    }
}

if ($loadingModule) {
    Export-ModuleMember -Function 'Deploy-QlikRules'
}