Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Qlikview Management Service with Powershell

Hello!

We are trying to use the QMS to make some of the mundane tasks of updating an installation easier to administer. Things like: changing the order in which applications load etc.

As we are not a .NET development company and thus don't want to maintain a Visual Studio project, we were planning to use Powershell to do this.

We have come this far with our script:

$service = New-WebServiceProxy -Uri http://someHost:4799/QMS/Service -Namespace QlikViewServer -Credential (get-credential)

$serviceKey = $service.GetTimeLimitedServiceKey()

$service.GetServices([QlikViewServer.ServiceTypes]::All, $true)

It seems to work fine until here. When we don't provide the credentials in step one, an authentication error is thrown when trying to get the service key. This way it returns what looks like a real key. Tells us that we are doing something right. But then we don't know what to do with the key afterwards.

We couldn't find the ServiceKeyClientMessageInspector class, mentioned at the QlikBlog.at

QlikView Management API - #2 Export / Add / Delete Document CALs

Any ideas? Either from Powershell-Webservice experience or because you are actually doing something similar?

Regards,

Sandro

13 Replies
Anonymous
Not applicable
Author

No takers for this one? 🙂

Bill_Britt
Former Employee
Former Employee

Hi,

I am not a programmer so I am not able to help you there. However, I would asked have you setup the Qlikview Management API group on the local machine and put the user that is running the script as a member of that group?

Bill

Bill - Principal Technical Support Engineer at Qlik
To help users find verified answers, please don't forget to use the "Accept as Solution" button on any posts that helped you resolve your problem or question.
Anonymous
Not applicable
Author

Hello Bill!

Finally got around to checking that. It is in the "QlikView Management API" group, the "QlikView Administrators" group and even the "QlikView EDX" group.

Thanks

Anonymous
Not applicable
Author

I'm trying the same and getting an error with GetServices. Has anyone used Powershell successfully to call the QliKVew Server API?

Cannot convert argument "serviceTypes", with value: "All", for "GetServices" to type "QlikViewServer.ServiceTypes": "Cannot convert value "All" to type

"QlikViewServer.ServiceTypes". Error: "Invalid cast from 'QlikViewServer.ServiceTypes' to 'QlikViewServer.ServiceTypes'.""

At C:\app\ACCE-MIS\qms.ps1:5 char:1

+ $service.GetServices([QlikViewServer.ServiceTypes]::All , $true )

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodException

    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Anonymous
Not applicable
Author

Just a hunch, but your error sounds like Powershell doesn't know that enumeration, yet.

From looking at the rest of the script: Why would it know QlikViewServer.ServiceTypes? How do you create the $service object? (same way I did?)

I am not near the test server right now, so can't check it myself if it is there or what the error message for me actually was

Sandro

Not applicable
Author

Hi Sandro,

As far as I can review, the ServiceKeyClientMessageInspector class is part of a wrapper for a class implementing IClientMessageInspector, the idea is to send a header called "X-Service-Key" with the value provided by GetTimeLimitedServiceKey(), so you can use it in every request, and the New-WebServiceProxy don´t provide a property/method to add a header (well I just googled it).

Have someone encountered a different way to communicate to the QMS API Service with PowerShell?

Regards,

Cristian

Anonymous
Not applicable
Author

Hi Sandro,

Did you get this to work ? I am also trying to use the QMS webservice from Powershell but haven't managed to get it to work sofar.

krumbein
Partner - Contributor III
Partner - Contributor III

Unfortunately I only have access to a QlikView Server in one particular customer project and that project right now doesn't allow any work on this. I'll have to see, when I'll find the time to try something on this again. Until we stopped working on this, I hadn't managed to get it to work

Sandro

analienx
Contributor III
Contributor III

Hello,

use following code and adjust it to your needs. Basically it enables you to connect to QMC (QMS) with the exported certificate. It is essential to have all the certificates and use the Client certificate - Exporting certificates through the QMC ‒ Qlik Sense.

$def =@"
public class ClientCertWebClient : System.Net.WebClient
{
    System.Net.HttpWebRequest request = null;
    System.Security.Cryptography.X509Certificates.X509CertificateCollection certificates = null;

     protected override System.Net.WebRequest GetWebRequest(System.Uri address)
     {
         request = (System.Net.HttpWebRequest)base.GetWebRequest(address);
         if (certificates != null)
         {
             request.ClientCertificates.AddRange(certificates);
         }
         return request;
     }

     public void AddCerts(System.Security.Cryptography.X509Certificates.X509Certificate[] certs)
     {
         if (certificates == null)
         {
             certificates = new System.Security.Cryptography.X509Certificates.X509CertificateCollection();
         }
         if (request != null)
         {
             request.ClientCertificates.AddRange(certs);
         }
         certificates.AddRange(certs);
     }
 }
"@;

Add-Type -TypeDefinition $def;

$xrfkey = "0123456789abcdef";
$req = New-Object ClientCertWebClient
# Overrided $req.Credentials = [System.Net.CredentialCache]::DefaultCredentials 

# LOAD CERTIFICATE FROM STORE00
$certs = Get-ChildItem ("Microsoft.PowerShell.Security\Certificate::LocalMachine\My\YOURCERTTHUMBPRINT");
$req.AddCerts($certs); 
$req.QueryString.Add("xrfkey", $xrfkey) ;
$req.Headers.Add("X-Qlik-xrfkey", $xrfkey);
$req.Headers.Add("X-Qlik-User", "UserDirectory=internal;UserId=qs_admin");
#$req.DownloadString(("https://CENTRALNODE:4242/QRS/app?xrfkey=" + $xrfkey));
$req.DownloadString(("https://CENTRALNODE:4242/qrs/about/api/description"));