11 Replies Latest reply: Oct 16, 2017 11:51 AM by René Heijnen RSS

    Qlikview Management Service with Powershell

    Sandro Krumbein

      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

        • Re: Qlikview Management Service with Powershell
          Sandro Krumbein

          No takers for this one? :-)

          • Re: Qlikview Management Service with Powershell
            Bill Britt

            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

            • Re: Qlikview Management Service with Powershell
              Paul Routledge

              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

              • Re: Qlikview Management Service with Powershell
                Cristian Casanova

                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

                • Re: Qlikview Management Service with Powershell
                  Sandro Krumbein

                  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

                  • Re: Qlikview Management Service with Powershell
                    Jakub Holasek

                    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"));
                    
                    
                    
                    
                    • Re: Qlikview Management Service with Powershell
                      René Heijnen

                      Hello there,

                       

                      I've been trying this for a long time now and I haven't really gotten any further than you in this Sandro.

                      The problem is that you somehow have to put the service key in the header.

                      soap_Services.PNG

                      with soap ui I get everything I want back successfully. The problem is that the command we're using New-WebServiceProxy doesn't allow a header to be added. Please see the following website: New-WebServiceProxy which explains the whole command.

                       

                      Now see the REST request: Invoke-RestMethod which does allow you to add a header.

                       

                      This is a common problem with powershell and soap. A possibility to use the new-webserviceproxy command is to send a soap envelope with it but I am a bad programmer. I don't really understand how I can utilize this in poiwershell.

                       

                      I hope there is someone here who can help us out with this whole thing because it's driving me crazy.

                       

                      Thanks,

                      René