Extract-AdminContent.ps1

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


    <# Enable -Confirm and -WhatIf. #>
    [CmdletBinding(SupportsShouldProcess = $true)]
    param(
    #[parameter(Mandatory=$false)]
    [switch] $IncludeDataConnections ,
    [switch] $IncludeRules ,
    [switch] $IncludeStreams ,
    [switch] $IncludeVirtualProxies,
    [switch] $IncludeApps ,
    [switch] $IncludeExtensions,
    [switch] $IncludeEverything,
    [parameter(Mandatory=$false)]
    [System.Management.Automation.PSCredential] $mycreds 
    )

    begin {
    }

    process {
        

                #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;
 
                                }
                }
'@

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Connect-Qlik

If($IncludeDataConnections.IsPresent -or $IncludeEverything.IsPresent){
$connections = Get-QlikDataConnection  
        foreach($connection in $connections){
         $connection | ConvertTo-Json | Out-File "C:\Migrate\data-connections\$($connection.name).json" 
        }
}
If($IncludeRules.IsPresent -or $IncludeEverything.IsPresent){Get-QlikRule  | ?{$_.type -like 'custom'} | ForEach-Object { $_ | ConvertTo-Json | Out-File ("C:\Migrate\rules\$( ($_.name -replace '(-|#|\||"|,|/|:|â|€|™|\?)', '' )).json") } }

If($IncludeStreams -or $IncludeEverything.IsPresent){Get-QlikStream   | ForEach-Object { $_ | ConvertTo-Json | Out-File "C:\Migrate\streams\$($_.name).json" }}


If($IncludeVirtualProxies -or $IncludeEverything.IsPresent){Get-QlikVirtualProxy  | ?{$_.prefix.Length -gt 0} | ForEach-Object { $_ | ConvertTo-Json | Out-File "C:\Migrate\virtualproxies\$($_.prefix).json" }}


If($IncludeApps -or $IncludeEverything.IsPresent){Get-QlikApp  | ?{$_.stream.name -like '*Everyone*'} | ForEach-Object { return Export-QlikApp -filename "C:\Migrate\apps\$($_.name).qvf" -id $_.Id  }}


If($IncludeExtensions -or $IncludeEverything.IsPresent){$extensions = gci C:\QlikShare\StaticContent\Extensions 
foreach($extension in $extensions){

    If( Test-path "C:\Migrate\extensions\$($extension.BaseName).zip") {
        Remove-item "C:\Migrate\extensions\$($extension.BaseName).zip" -ErrorAction SilentlyContinue -Force 
    }

    Add-Type -AssemblyName "System.IO.Compression.FileSystem"
    [System.IO.Compression.ZipFile]::CreateFromDirectory($extension.FullName, ("C:\Migrate\extensions\"+ $extension.BaseName + ".zip") )  
 }
}



        }

    end {
    }
}

if ($loadingModule) {
    Export-ModuleMember -Function 'Extract-AdminContent'
}