Export-QlikCertificates.ps1

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


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

    [SecureString]$certificatePassword,
    [switch]$includeSecretsKey,
    [ValidateSet("Windows", "Pem")]
    [String]$exportFormat="Windows"
    )

    begin {
    }

    process {
    Write-Verbose "Export path: $(Get-QlikCertificateDistributionPath)"
    $body = @{
      machineNames = @( $machineNames );
    }
    If( $certificatePassword ) { $body.certificatePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($CertificatePassword)) }
    If( $includeSecretsKey ) { $body.includeSecretsKey = $true }
    If( $exportFormat ) { $body.exportFormat = $exportFormat }
    $json = $body | ConvertTo-Json -Compress -Depth 10

    return Invoke-QlikPost "/qrs/certificatedistribution/exportcertificates" $json
  }

    end {
    }
}

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