Citrix XenDesktop 7 – Create Persistent Hypervisor Connection and Hosting Unit, Unattended

· 4 min read

I blogged about how to automate Citrix XenDesktop 7 deployment and database creation, and how to join and existing XenDesktop 7 site unattended, but now to continue and go a bit further in the automation process, I needed and wanted to know how to automate Hosting Configuration by Adding Connection and Resources to the DDC in an unattended way.

This blog will cover creation process for XenServer 6.x and vCenter (vSphere) 5.1 since I don’t have access to a Hyper-V (yet), I went over Citrix eDoc to check how I could do this and I found here : [link]

Thanks to Livio for some PowerShell help 🙂

To Create a Persistent Hypervisor Connection
 
        new-item -path "xdhyp:Connections" -Name MyConn -ConnectionType
            XenServer -HypervisorAddress "http:address" -UserName user
            -Password password -Persist
 
        PSPath:                   Citrix.HostingUnitService.Admin.V1.0
                                  Citrix.Hypervisor::XDHyp:ConnectionsMyConn
        PSParentPath:             Citrix.HostingUnitService.Admin.V1.0
                                  Citrix.Hypervisor::XDHyp:Connections
        PSChildName:              MyConn
        PSDrive:                  XDHyp
        PSProvider:               Citrix.HostingUnitService.Admin.V1.0
                                  Citrix.Hypervisor
        PSIsContainer:            True
        HypervisorConnectionUid:  04e6daa2-5cbd-4491-b70c-6daf733ee82a
        HypervisorConnectionName: MyConn
        ConnectionType:           XenServer
        HypervisorAddress:        {http:address}
        UserName:                 user
        Persistent:               True
        PluginId:                 XenFactory
        SupportsPvsVMs:           True
        Revision:                 1b0b0d02-bc1b-49d8-b2b0-be6fb7f150ad
        MaintenanceMode:          False
        Metadata:                 {MaxAbsoluteActiveActions = 100,
                                  MaxAbsoluteNewActionsPerMinute = 100,
                                  MaxPowerActionsPercentageOfDesktops = 20}
 
    To Create a Hosting Unit
 
        new-item -Path "xdhyp:HostingUnits"
            -Name MyHU
            -HypervisorConnectionName MyConn
            -RootPath XDHYP:ConnectionsMyConn
            -NetworkPath XDHYP:ConnectionsMyConnNetwork 0.network
            -StoragePath XDHYP:ConnectionsMyConnLocal storage on
            myXenServer.storage
 
        PSPath:               Citrix.HostingUnitService.Admin.V1.0
                              Citrix.Hypervisor::XDHyp:HostingUnitsMyHU
        PSParentPath:         Citrix.HostingUnitService.Admin.V1.0
                              Citrix.Hypervisor::XDHyp:HostingUnits
        PSChildName:          MyHU
        PSDrive:              XDHyp
        PSProvider:           Citrix.HostingUnitService.Admin.V1.0
                              Citrix.Hypervisor
        PSIsContainer:        True
        HostingUnitUid:       df91f886-1141-4280-bd59-2ee260a4df79
        HostingUnitName:      MyHU
        HypervisorConnection: MyConn
        RootPath:             /
        RootId:
        NetworkPath:          /Network 0.network
        NetworkId:            ab47080b-ca15-771a-c8dc-6ad9650158f1
        Storage:              {/Local storage on myXenServer.storage}
        VMTaggingEnabled:     True
        Metadata:             {}
 
        Relative paths can be used for all parameters.

It helps to understand whet need to be setup and after few tests I ended up writing this script to automate this part :

###############################################
#
# Stephane Thirion - www.archy.net - @archynet
# This script is part from the blog post :
# 
# 7th July 2013 - XenDesktop 7 automation - Tested with XenServer 6.2 and vmware vSphere 5.1
#
# Make changes in the top of the file to reflect your installation
# 
# $HypervisorAddress = "" use an IP or FQDN with http or https if you use vCenter, don't forget to add /sdk 
# $ConnectionType = "XenServer" for XenServer value = XenServer , vmware = VCenter
# $HypervisorConnectionName = "WhateverTheNameYouWantToUse"
# $Networkpath = "Host Networkname You Want To Use" Just copy and past from XenCenter
# $StoragePath = "Name of the Storage you want to use"  Just copy and past from XenCenter
# $PersonalvDiskStoragePath = "Name of the Storage you want to use for pvDisk"  Just copy and past from XenCenter
# $StorageNetworkResourceName = "WhateverTheNameYouWantToUse"
#
###############################################
$HypervisorAddress = ""
$ConnectionType = "XenServer"
$HypervisorConnectionName = "HypervisorFORXD7"
$Networkpath = "Bond 1+2"
$StoragePath = "NAS VDI"
$PersonalvDiskStoragePath = "NAS VDI"
$StorageNetworkResourceName = "StorageNetworkResourceXD7"
 
###############################################
# Hypervisor user credentials
###############################################
$HypervisorUser = "user"
$HypervisorPassword = "password"
 
###############################################
#
# DO NOT EDIT ANYTHING BELLOW THIS LINE
#
###############################################
# Create Connection 
###############################################
Get-ConfigServiceStatus  -AdminAddress $env:COMPUTERNAME
 
Get-LogSite  -AdminAddress $env:COMPUTERNAME
 
New-Item  -AdminAddress $env:COMPUTERNAME -ConnectionType $ConnectionType -HypervisorAddress @($HypervisorAddress) -Path xdhyp:connections$HypervisorConnectionName -Scope @() -Password $HypervisorPassword -UserName $HypervisorUser
 
###############################################
# Update Connection 
###############################################
Get-ConfigServiceStatus  -AdminAddress $env:COMPUTERNAME
 
Get-LogSite  -AdminAddress $env:COMPUTERNAME
 
Set-Item  -AdminAddress $env:COMPUTERNAME -PassThru -Path xdhyp:connections$HypervisorConnectionName -Password $HypervisorPassword -UserName $HypervisorUser
 
###############################################
# Create Resources and Persist Connection
###############################################
Get-ConfigServiceStatus  -AdminAddress $env:COMPUTERNAME
 
Get-LogSite  -AdminAddress $env:COMPUTERNAME
 
Get-Item  -AdminAddress $env:COMPUTERNAME -Path xdhyp:connections$HypervisorConnectionName
 
Remove-Item  -AdminAddress $env:COMPUTERNAME -Path xdhyp:connections$HypervisorConnectionName
 
New-Item  -AdminAddress $env:COMPUTERNAME -ConnectionType $ConnectionType -HypervisorAddress @($HypervisorAddress) -Path xdhyp:connections$HypervisorConnectionName -Persist -Scope @() -Password $HypervisorPassword -UserName $HypervisorUser
 
$HypervisorConnectionUid = (Get-Item  -AdminAddress $env:COMPUTERNAME -Path xdhyp:connections$HypervisorConnectionName).HypervisorConnectionUid.ToString()
 
New-BrokerHypervisorConnection  -AdminAddress $env:COMPUTERNAME -HypHypervisorConnectionUid $HypervisorConnectionUid
 
New-Item  -AdminAddress $env:COMPUTERNAME -HypervisorConnectionName $HypervisorConnectionName -NetworkPath xdhyp:connections$HypervisorConnectionName$NetworkPath.network -Path xdhyp:hostingunits$StorageNetworkResourceName -PersonalvDiskStoragePath xdhyp:connections$HypervisorConnectionName$PersonalvDiskStoragePath.storage -RootPath xdhyp:connections$HypervisorConnectionName -StoragePath xdhyp:connections$HypervisorConnectionName$StoragePath.storage

 

This script have been tested with Citrix XenDesktop7 and XenServer 6.2 and vSphere 5.1