0 Replies Latest reply on Mar 16, 2016 6:35 PM by ccurry

    Powershell Token Authentication when connecting to vRealize Business Standard 7.0

    ccurry Lurker

      Following the documentation for vRealize Business Standard (vRealize Business Standard 7.0 Documentation Center) I have been trying to write a Powershell script to retrieve a token from the vRealize Automation server and pull an out-of-the-box report from the vRealize Business Standard server. After successfully retrieving the token, I hit the following error when connecting to the Business Standard server:


      Invoke-RestMethod : HTTP Status 401 - Authentication required

      type Status report

      message Authentication required

      description This request requires HTTP authentication.

      Pivotal tc Runtime 3.1.0. RELEASE/8.0.20.B.RELEASE


      The script I'm running is below:


      #Script found online to bypass Self-Signed Certificate issues.

      add-type @"

          using System.Net;

          using System.Security.Cryptography.X509Certificates;

          public class TrustAllCertsPolicy : ICertificatePolicy {

              public bool CheckValidationResult(

                  ServicePoint srvPoint, X509Certificate certificate,

                  WebRequest request, int certificateProblem) {

                  return true;




      [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy


      $username = "[username]"

      $password = "[password]"

      $auth = $username + ':' + $password

      $encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)

      $encodedPassword = [System.Convert]::ToBase64String($encoded)


      $tokenHeaders = @{"Accept" = "application/json"}


      $credentials = @{

          username = $username;

          password = $password;

          tenant = "[tenant]"



      $token = Invoke-RestMethod -Uri "https://[vRealizeAutomationServer]/identity/api/tokens" -Method Post `

          -Headers $tokenHeaders -ContentType "application/json" `

          -Body (ConvertTo-Json $credentials) | Select -ExpandProperty id


      echo "Token: $token"

      $reportHeaders = @{"Accept" = "text/plain"}

      $reportHeaders.Add("Authorization", "Bearer $token")

      $results = Invoke-RestMethod -Uri "https://[vRealizeBusinessServer]/itfm-cloud/rest/reports/export-filters/servers" -Method Get `

          -Headers $reportHeaders -ContentType "text/plain"

      The lines used to create $encodedPassword was part of an experiment to authenticate with username/password instead of a token. The error is caused by the second Invoke-RestMethod. I am using Powershell version 4.0


      I haven't been able to find any other documented cases of Powershell being used for this purpose, and minimal material on using tokens with Invoke-RestMethod. Can anyone help point me in the right direction here? Thank you.


      Further details in this post, after I tried the same call with wget: Pulling Reports from vRealize Business Standard Server Public API