Skip to content

Instantly share code, notes, and snippets.

@levi-turner
Created May 15, 2020 01:16
Show Gist options
  • Save levi-turner/d2c99cb4695379b744aea26de8b5e97e to your computer and use it in GitHub Desktop.
Save levi-turner/d2c99cb4695379b744aea26de8b5e97e to your computer and use it in GitHub Desktop.
$objects = @(
'7e54b526-31d5-4599-9af3-38c53ec47042',
'33d2f127-ae6c-4357-855f-ca3d405a6e93',
'87d82e26-48bf-4eb8-9bef-08670cf630d4',
'f6e9214c-2c73-4e8c-b754-a6b0ddc577b7',
'f86b8007-5d76-4d8c-a33e-d9fa50a26836'
)
# Build out headers for QRS API Calls
$hdrs = @{}
$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")
$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")
# Get the certificate
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}
# Check for the cert
if (!$cert) {
Write-Host "Client certificate not found" -ForegroundColor Red
Exit
}
# Construct the host to call
$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg
$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))
if (!$Data) {
Write-Host "Host.cfg file not found. Ensure script is run on a Qlik Sense node" -ForegroundColor Red
Exit
} else {
Write-Host "Attempting to connect to $FQDN" -ForegroundColor Green
}
# Handle TLS 1.2 exclusive environments
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
# Test call /qrs/about to ensure connectivity
$about = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/about?xrfkey=examplexrfkey123" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert
if (!$about) {
Write-Host "Unable to contact QRS at $($FQDN)" -ForegroundColor Red
Exit
} else {
Write-Host "Connected to $FQDN" -ForegroundColor Green
}
$objects | ForEach-Object {
$body =''
Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/object/$_/publish?xrfkey=examplexrfkey123" -Method Put -Headers $hdrs -ContentType 'application/json' -Certificate $cert
Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/object/$_/approve?xrfkey=examplexrfkey123" -Method Post -Headers $hdrs -ContentType 'application/json' -Certificate $cert
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment