Qlik Community

QlikView Management

Discussion Board for collaboration on QlikView Management.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator
Creator

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
Highlighted
Creator
Creator

Re: Qlikview Management Service with Powershell

No takers for this one? 🙂

Highlighted
Support
Support

Re: Qlikview Management Service with Powershell

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 - Designated 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.
Highlighted
Creator
Creator

Re: Qlikview Management Service with Powershell

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

Highlighted
Creator II
Creator II

Re: Qlikview Management Service with Powershell

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

Highlighted
Creator
Creator

Re: Qlikview Management Service with Powershell

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

Highlighted
Not applicable

Re: Qlikview Management Service with Powershell

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

Highlighted
Contributor III
Contributor III

Re: Qlikview Management Service with Powershell

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.

Highlighted
Partner
Partner

Re: Qlikview Management Service with Powershell

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

Highlighted
Contributor III
Contributor III

Re: Qlikview Management Service with Powershell

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"));