Create a new VMware vCenter Hosting Connection with SSL Trust in Citrix 7.x with PowerShell

Just a small new blog, as you know my motto is “Automate Everything”! Well, the past weeks I’ve been busy with just that. I’m at a customer and we are creating a completely automated Citrix 7.15.1 Environment deployment. And one problem I ran into was adding the vCenter connection into hosting through PowerShell. I found this blog on the Citrix blogs about this topic: https://www.citrix.com/blogs/2013/10/30/scripting-howto-xendesktop-7-hosting-configuration/

But the script in the blog will give a certificate error because you need to import and trust the vCenter certificate to use it as a hosting connection. So I created the script below to download the certificate from the URL, import the certificate, get the thumbprint and create a hosting connection in Citrix XenDesktop 7.X

I hope this was informative. For questions or comments you can always give a reaction in the comment section or contact me:

6 thoughts on “Create a new VMware vCenter Hosting Connection with SSL Trust in Citrix 7.x with PowerShell

  1. Hi Chris,
    Thank you so much for sharing this script. I am a bit new to Powershell and could do with your help on how I should execute the script on the delivery controller.
    I saved the script as Import_vCenter_Cert.ps1 but i am a bit confused as to how I should provide the input parameters for the vCenter URL, user ID and Password.

    Hope you can shed some light on the above.

    Regards,
    Mark

    1. Hi Mark,

      Great that you are starting to use PowerShell it’s really important in the IT these days.
      The script in the blog is a function so you need to import the function and then run it.
      The easiest way to do this is to open your .ps1 in a PowerShell editor like Visual Studio Code or the built-in PowerShell ISE.
      Then add a extra line in the bottom like: New-vCenterHostConnection -vCenterURL “https://vcenter.domain.com” -vCenterUsername “DOMAIN\Administrator” -vCenterPassword ‘Password01’
      And then run the script (F5). Hope this helps !

      Gr. Chris

  2. Hi Chris,
    I am trying to automate the install and and basic config of XD7.15 for use in my training lab, I am learning the basics of scripting. I tried what you suggested but for some reason I keep getting the below output errors when I run the script. The vCenter and Delivery Controller servers are running on a WS2016.

    New-vCenterHostConnection -vCenterURL “https://vc01.lab.local” -vCenterUsername “vi-admin@lab.local” -vCenterPassword ‘P@ssw0rd’

    Create hosting connection to https://vc01.lab.local
    Exception calling “GetResponse” with “0” argument(s): “The underlying connection was closed: An unexpected error occurred on a send.”
    At C:\Logs\Import_vCenter_Certificate.ps1:70 char:5
    + $response = $request.GetResponse()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

    You cannot call a method on a null-valued expression.
    At C:\Logs\Import_vCenter_Certificate.ps1:72 char:5
    + $certBytes = $certificate.Export(
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Exception calling “WriteAllBytes” with “2” argument(s): “Value cannot be null.
    Parameter name: bytes”
    At C:\Logs\Import_vCenter_Certificate.ps1:74 char:5
    + [System.IO.File]::WriteAllBytes($OutputFile, $certBytes)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    Exception calling “Import” with “1” argument(s): “The system cannot find the file specified.

    At C:\Logs\Import_vCenter_Certificate.ps1:77 char:5
    + $certPrint.Import(“$path\vmware.cer”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CryptographicException

    New-Item : No objects were found.
    At C:\Logs\Import_vCenter_Certificate.ps1:78 char:22
    + … ectionuid = New-Item -ConnectionType “VCenter” -CustomProperties “” – …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [New-Item], InvalidOperationException
    + FullyQualifiedErrorId : Citrix.XDPowerShell.HostStatus.ObjectsNotFound,Microsoft.PowerShell.Commands.NewItemCommand

    New-Item : No objects were found.
    At C:\Logs\Import_vCenter_Certificate.ps1:78 char:22
    + … ectionuid = New-Item -ConnectionType “VCenter” -CustomProperties “” – …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-Item], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.NewItemCommand

    New-BrokerHypervisorConnection : Cannot bind argument to parameter ‘HypHypervisorConnectionUid’ because it is null.
    At C:\Logs\Import_vCenter_Certificate.ps1:79 char:85
    + … L” -HypHypervisorConnectionUid $connectionuid.HypervisorConnectionUid
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [New-BrokerHypervisorConnection], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Citrix.Broker.Admin.SDK.NewBrokerHypervisorConnectionCommand

    1. Hi Mark,

      Try running the script as Administrator so open VS Code or PowerShell ISE with right mouse run as Administrator. And run the script from you delivery controller.
      You can check if you get a vmware.cer in your %temp% folder.

      Gr. Chris

Leave a Reply

Your email address will not be published. Required fields are marked *