Qlik Sense Cmdlet
for PowerShell
Sokkorn CHEAV
Qlik Sense Cmdlet for PowerShell
Table of Contents
1. Introduction........................................................................................................................................................2
2. Why this document? ..........................................................................................................................................2
3. Tested Environment ...........................................................................................................................................2
4. Installation..........................................................................................................................................................2
6. Command Test Case ...........................................................................................................................................4
6.1 View a list of available commands ............................................................................................................. 4
6.2 View help for specific command ................................................................................................................ 4
6.3 Connect to Qlik Sense Server ..................................................................................................................... 4
6.4 Import QVF ................................................................................................................................................. 5
6.5 Publish QVF ................................................................................................................................................ 5
6.6 Trigger Task ................................................................................................................................................ 6
6.7 Export QVF ................................................................................................................................................. 7
6.8 Auto Import and Publish App Using Window Task Schedule ..................................................................... 7
6.9 Archive QVF and delete backup files older than 7 days............................................................................. 9
Page 1 of 10
Qlik Sense Cmdlet for PowerShell
1. Introduction
Qlik-Cli is a PowerShell module that provides a command line interface for managing a Qlik Sense
environment. The module provides a set of commands for viewing and editing configuration settings, as
well as managing tasks and other features available through the APIs.
You can find original Qlik-Cli in GitHub by click this link
2. Why this document?
The main purpose of this document is to provide some of use case function where we can’t find in GitHub.
A common scenario:
a. Triggering tasks from an external application
b. Auto import and publish app to QMC
c. Backup QVF
3. Tested Environment
Below server environment has been successfully tested with
1. Windows Server 2016 Standard
2. Qlik Sense June 2017
4. Installation
The installation of Qlik-Cli is very simple. Here is the step:
1. Download the package from here
2. Extract the package into [C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Qlik-Cli]
Page 2 of 10
Qlik Sense Cmdlet for PowerShell
MUST READ:
a. If you download package from point 4.1 and has same “Tested Environment”, no issue occur.
b. If you download package from original GitHub and has same “Tested Environment”, the PowerShell
will not work. To overcome the issue, you must amend script in file “Qlik-Cli.psm1” by adding
$result = Invoke-WebRequest -Uri "https://IpAddress/resource"
below line
[System.Net.ServicePointManager]::CertificatePolicy = New-Object
TrustAllCertsPolicy
Page 3 of 10
Qlik Sense Cmdlet for PowerShell
6. Command Test Case
6.1 View a list of available commands
Command:
Get-Help Qlik
6.2 View help for specific command
Command:
Get-Help Connect-Qlik
6.3 Connect to Qlik Sense Server
Command:
Connect-Qlik
Page 4 of 10
Qlik Sense Cmdlet for PowerShell
6.4 Import QVF
Command:
# Step 1: Connect to Qlik Sense Server (start session)
# - Change QS to your Qlik Sense server name
Connect-Qlik QS -useDefaultCredentials
# Step 2: Import QVF
Import-QlikApp -file "C:\myQVF\Executive Dashboard.qvf" -name "Executive Dashboard" -upload
6.5 Publish QVF
Command:
# Step 1: Connect to Qlik Sense Server (start session)
# - Change QS to your Qlik Sense server name
Connect-Qlik QS -useDefaultCredentials
# Step 2: Publish QVF
Publish-QlikApp -id "8c6b1568-7bb0-47bc-a9c9-a90b18b56975" -stream "Executive" -name "Executive Dashboard"
Page 5 of 10
Qlik Sense Cmdlet for PowerShell
6.6 Trigger Task
Command:
# Step 1: Connect to Qlik Sense Server (start session)
# - Change QS to your Qlik Sense server name
Connect-Qlik QS -useDefaultCredentials
# Step 2: Trigger task
Start-QlikTask "Reload task of Operations Monitor" -wait | Wait-QlikExecution
Page 6 of 10
Qlik Sense Cmdlet for PowerShell
6.7 Export QVF
Command:
# Step 1: Connect to Qlik Sense Server (start session)
# - Change QS to your Qlik Sense server name
Connect-Qlik QS -useDefaultCredentials
# Step 2: Export QVF
# Sample export using app id
Export-QlikApp -id "8c6b1568-7bb0-47bc-a9c9-a90b18b56975" -filename "C:\myQVF\myExportApp - Operations
Monitor.qvf"
# Sample export using app name
$QVF_Name_In_QMC = "License Monitor"
Export-QlikApp -id $(Get-QlikApp -filter "name eq '$QVF_Name_In_QMC'").id -filename "C:\myQVF\myExportApp -
$QVF_Name_In_QMC.qvf"
6.8 Auto Import and Publish App Using Window Task Schedule
Command:
# Step 1: Connect to Qlik Sense Server (start session)
# - Change QS to your Qlik Sense server name
Connect-Qlik QS -useDefaultCredentials
# Step 2: Import Qlik Sense App
# - In QMC will show "myHelpdeskManagement" under Apps name
Import-QlikApp -name "myHelpdeskManagement" -file "C:\myQVF\Helpdesk Management.qvf" -upload
# Step 3: Publish Qlik Sense App to Stream
# - "Support" is a stream name
Publish-QlikApp -id $(Get-QlikApp -filter "name eq 'myHelpdeskManagement'").id -stream $(Get-
QlikStream -filter "name eq 'Support'").id -name "myHelpdeskManagement"
Copy script into notepad and save as Import_n_Publish.ps1
Create “Task Schedule”
Page 7 of 10
Qlik Sense Cmdlet for PowerShell
Add “Action”
a. Action : Start a program
b. Program/Script : PowerShell.exe
c. Add arguments (optional) : -ExecutionPolicy Bypass C:\myQVF\Import_n_Publish.ps1
Page 8 of 10
Qlik Sense Cmdlet for PowerShell
6.9 Archive QVF and delete backup files older than 7 days
Scenario:
1. Everyday we want to export QVF from QMC into a backup folder and name it something like
“YYYYMMDD – License Monitor.qvf”
2. We want to create a backup directory automatically if it not exists. Ex. C:\QVF_Backup
3. We want to delete QVF files where age older than 7 days
Page 9 of 10
Qlik Sense Cmdlet for PowerShell
Below command will handle above scenario:
#=========================================================================
# Use Case:
# 1. Everyday we want to export QVF from QMC into a backup folder
# and name it something like “YYYYMMDD – License Monitor.qvf”
# 2. We want to create a backup directory automatically if it
# not exists. Ex. C:\QVF_Backup
# 3. We want to delete QVF files where age older than 7 days
#-------------------------------------------------------------------------
# Step 1: Declare global variables
$Path_Backup = "C:\QVF_Backup"
$Today = Get-Date -format "yyyyMMdd"
# Step 2: Create backup directory if it not exist
If(!(test-path $Path_Backup))
{
New-Item -ItemType Directory -Force -Path $Path_Backup
}
# Step 3: Connect to Qlik Sense Server (start session)
# - Change QS to your Qlik Sense server name
Connect-Qlik QS -useDefaultCredentials
# Step 4: Only Export and Delete old QVF if reload task FinishedSuccess
$GetTaskStatus = $(Get-QlikTask -filter "name eq 'Reload License Monitor'").status
If ($GetTaskStatus -eq "FinishedSuccess")
{
#Export QVF
$QVF_Name_In_QMC = "License Monitor"
Export-QlikApp -id $(Get-QlikApp -filter "name eq '$QVF_Name_In_QMC'").id -filename
"$Path_Backup\$Today - $QVF_Name_In_QMC.qvf"
#Delete files older than 7 days
Get-ChildItem $Path_Backup -Recurse | Where-Object { $_.LastWriteTime -lt (Get-
Date).AddDays(-7) } | Remove-Item
}
Copy script into notepad and save as Archive_QVF.ps1
Create “Task Schedule” (please refer to 6.8)
Page 10 of 10