XenDesktop 5 PowerShell SDK Primer – Part 2 – Creating Hypervisor Connections and Hosts
One of the new changes that you will see in XenDesktop 5 is the configuration of hypervisor connectionsand hosts. In order to create the “pooled”, “dedicated”, or “existing” catalog types in XenDesktop 5, XenDesktop needs to know details of the hypervisor that will be hosting the virtual desktops. Hypervisor connection details are also required in order to manage virtual desktops from within Desktop Studio, such as powering on and restarting virtual desktops. Hypervisor connections and hosts can be created manually within Desktop Studio or automated using the PowerShell SDK. The focus of this article will be on the automation of this configuration using PowerShell.
This is the second blog in a series on how to use the XenDesktop 5 PowerShell SDK. In the first blog, I provided info on how to get started with the SDK, some approaches you can take for learning the cmdlets, some reference web pages that you can bookmark, and the tools you can use for creating your own scripts. If you haven’t read that article yet, please visit that blog first. For a complete list of topics that I will be covering in this series, see the bottom of this article.
What are Hypervisor Connections and Hosts within XenDesktop 5?
Hypervisor connections and hosts are one of the first items that you typically configure in a XenDesktop 5 deployment. They are configured within the Hosts node of the Desktop Studio Console. If you were to configure this manually in the console, you would click Add Host and run through a short wizard to configure both at the same time (see screen shot below). In short…
- Connections represent a “connection” to a specific hypervisor type (XenServer, Hyper-V, etc). This connection contains the address, username, and password for communicating to that hypervisor. If you want to tie your XenDesktop deployment to multiple hypervisor types, you will have multiple connections defined.
- Hosts represent a “server” that leverages the hypervisor connection. A hypervisor connection can have one or several hosts tied to it, depending on whether the hypervisor deployment is a single server or a pool of servers. The host configuration consists of the name of the “hosting unit”, the “guest network” used by the virtual desktops on the host, and the “storage repository” used by the virtual desktops on the host.
PowerShell Script for creating Hypervisor Connections and Hosts
The sample script below demonstrates how to create a hypervisor connection and host within XenDesktop 5. This script references a XenServer host that has a storage repository called “Local Storage” and a guest network called “Internal”.
#***************************************************************
#Write debug message to signify start of script
#***************************************************************
$objDateTime = Get-Date
Write-Host ""
Write-Host "*****Script started at" $objDateTime "*****" #***************************************************************
#Add Citrix snapins to PowerShell session if not already added
#***************************************************************
$snapins = Get-PSSnapin | where { $_.Name -like "Citrix*" }
if (($snapins -eq $null) -or ($snapins.Count -ne 8))
{
Write-Host "Loading the XenDesktop cmdlets into this session..."
Get-PSSnapin -Registered "Citrix*" | Add-PSSnapin
Add-PSSnapin "PvsPsSnapin"
}
else
{
Write-Host "XenDesktop cmdlets are already loaded into this session..."
} #*****************************************************************************
#Global variables for entire script
#*****************************************************************************
$strXenServerHostname = "173.192.71.99"
$strXenServerUsername = "root"
$strXenServerPassword = "Password1"
$strHypervisorConnectionName = "XenServer Connection"
$strHypervisorType = "XenServer"
$strHypervisorAddress = "http://" + $strXenServerHostname
$strGuestNetworkName = "Internal" #Use the "Internal" network defined on XenServer
$strStorageName = "Local Storage" #Use the "Local Storage" SR defined on XenServer
$strDDCAddress = "ddc1.xendesktop.lab:80" #*****************************************************************************
#Create hypervisor connection
#*****************************************************************************
$objHypConn = New-Item -Path 'xdhyp:\connections' -Name $strHypervisorConnectionName -HypervisorAddress $strHypervisorAddress -ConnectionType $strHypervisorType -Username $strXenServerUsername -Password $strXenServerPassword -Persist -AdminAddress $strDDCAddress
$objHypConnection = New-BrokerHypervisorConnection -HypHypervisorConnectionUid $objHypConn.HypervisorConnectionUid -AdminAddress $strDDCAddress
if ($objHypConnection -ne $null)
{
#Write debug message
Write-Host "Successfully created hypervisor connection to" $strHypervisorAddress
}
else
{
#Write debug message
Write-Host "ERROR: Could not create hypervisor connection to" $strHypervisorAddress
} #*****************************************************************************
#Add host to the hypervisor connection
#*****************************************************************************
$strHostUnitName = $strXenServerHostname.Replace(".", "-") #Periods are not accepted in the hosting unit name
$strRootPath = "xdhyp:\connections\" + $strHypervisorConnectionName
$strNetworkPath = $strRootPath + "\" + $strGuestNetworkName + ".network"
$strStoragePath = $strRootPath + "\" + $strStorageName + ".storage"
$objHostUnits = New-Item -Path 'xdhyp:\hostingunits' -Name $strHostUnitName -HypervisorConnectionName $objHypConnection.Name -RootPath $strRootPath -NetworkPath $strNetworkPath -StoragePath $strStoragePath -AdminAddress $strDDCAddress
if ($objHostUnits -ne $null)
{
#Write debug message
Write-Host "Successfully added host called" $strHostUnitName "to the hypervisor connection..."
}
else
{
#Write debug message
Write-Host "ERROR: Could not add host to the hypervisor connection..."
} #***************************************************************
#Write debug message to signify end of script
#***************************************************************
$objDateTime = Get-Date
Write-Host "*****Script ended on" $objDateTime "*****"
Write-Host ""
Note: The sample script above performs some basic error handling to help you keep track of the automation status. It outputs the success or failure of key sections of the script to the PowerShell window. The expected output is shown below. If you run into any issues, you can use a PowerShell editor such asPowerGui.exe to step through each line of the script.
After the script is executed, you can open the Desktop Studio console to verify the hypervisor connection and host configuration are present (see screen shot below).
Analyzing the PowerShell Script
The top of the script has a section on loading the XenDesktop PowerShell snap-ins. This is needed to ensure we can call the XenDesktop cmdlets no matter how you choose to execute the script (Standard PowerShell window, PowerGui.exe, etc.). You’ll see this same code snippet at the top of all my XenDesktop 5 scripts.
Next, the Global Variables section defines the information specific to my environment. This is the information that you would have normally configured if you were to run through the wizard in Desktop Studio. This should be the only section that you need to touch to ensure that the script can run within your own environment. You’ll want to change the values here to reference your own hypervisor connection and host.
Once the global variables are defined, the good stuff really starts. Creating a hypervisor connection and host takes three cmdlet calls. You will reference the New-Item and New-BrokerHypervisorConnection cmdlets. If you want to experiment some more, you can also play with the Get-BrokerHypervisorConnection cmdlet to see the properties of an existing hypervisor connection.
#Get reference to an existing hypervisor connection with the specified name
$objHypConnection = Get-BrokerHypervisorConnection -Name "XenServer Connection"
A lot of the code within this script is for the error checking. To check for errors, I’m placing the output of the cmdlets into variables. The output of these particular cmdlets are all objects. I’m then checking if that object is null. If it’s not null, I know I have a valid reference to that object and that cmdlet executed successfully. If it’s null, I know some error occurred. You can enhance this error checking even more by preventing the script from proceeding further should an error come up.
XenDesktop 5 PowerShell SDK Primer – Part 2 – Creating Hypervisor Connections and Hosts的更多相关文章
- [Redis]如何通过Powershell创建Redis服务
目前Redis在中国上线了,不过只是预览版而且不能通过Portal进行操作,不过可以通过Powershell创建,具体如下: 下载最新的Powershell SDK:http://www.window ...
- 作为平台的Windows PowerShell(二)
在此系列文章的前一篇,我们看到了怎样使用System.Management.Automation.PowerShell 类来在c#应用程序中运行PowerShell 命令.在那些例子中,我们创建的都是 ...
- Azure 基础:使用 powershell 创建虚拟网络
什么是虚拟网络 虚拟网络是您的网络在 Azure 云上的表示形式.您可以完全控制虚拟网络的 IP 地址.DNS 的设置.安全策略和路由表.您还可以更进一步,把虚拟网络划分为多个子网.然后用它们连接您的 ...
- dotnet core 使用 PowerShell 脚本
本文告诉大家如何在 dotnet core 通过 Host PowerShell 的方法使用 PowerShell 脚本 本文提供的方法需要在 dotnet core 2.1 和以上的版本,对于 do ...
- 【Azure 环境】使用Microsoft Graph PS SDK 登录到中国区Azure, 命令Connect-MgGraph -Environment China xxxxxxxxx 遇见登录错误
问题描述 通过PowerShell 连接到Microsoft Graph 中国区Azure,一直出现AADSTS700016错误, 消息显示 the specific application was ...
- Android sdk manager不能更新下载缓慢的解决方法
通常情况下,下载Android SDK需要连接谷歌的服务器进行下载,由于国内水深火热的网络,速度基本为0.好在国内也有一个更新的镜像地址.本文章介绍如何在不FQ的情况下,使用国内镜像地址,更新andr ...
- android自定义控件一站式入门
自定义控件 Android系统提供了一系列UI相关的类来帮助我们构造app的界面,以及完成交互的处理. 一般的,所有可以在窗口中被展示的UI对象类型,最终都是继承自View的类,这包括展示最终内容的非 ...
- JDBC API Description
package java.sql description What the JDBCTM 4.2 API Includes Versions What the java.sql Package Con ...
- P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1
P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1 May ...
随机推荐
- Jenkins的安全控制
在默认配置下,Jenkins是没有安全检查的.任何人都可以以匿名用户身份进入Jenkins,设置Jenkins和Job,执行build操作.但是,Jenkins在大多数应用中,尤其是暴露在互联网的应用 ...
- Error: Linux下 mysql.sock文件丢失被删除解决方法
在默认情况下,Mysql安装以后会在/tmp目录下生成一个mysql.sock文件,如该文件丢失则Mysql将不能够正常启动,解决方法:使用mysqld_safe 启动即可解决: #basedir:m ...
- Server(Iocp)的那些烦恼
自G-Socket0.88版开源以来,得到很多朋友的支持.从1.0版本至2.0之前,内核几乎没有改变,经过多处的应用其稳定性和效率表现是相当不错的.这几年的经验总结成一句话:服务器程序不是有了一个好的 ...
- Malloc碎碎念
(以前为给同学分享写的点东西,很基础.)现在的比赛中堆溢出非常常见,对于glibc下malloc的理解也要深入一些. malloc_chunk的对齐属性 在glibc中,malloc_chunk以 2 ...
- VS2015 企业版不支持 JavaScript 语法高亮、智能提醒
2015年7月,微软终于放出了 Visual Studio 2015 正式版,博主安装了 Visual Studio 2015 企业版之后,居然不支持 JavaScript 的语法高亮.智能提醒功能, ...
- Linux学习1——首次登录
一.写在前面 在本节将介绍首次登录Linux系统(本文中为CentOS)所需要了解的一些基本操作.二.完成目标 1.了解GNOME和KDE窗口管理程序 2.使用在线求助man和info 3.基本命令操 ...
- iOS开发之网络请求(基于AFNetworking的再封装)
最近一直很忙也没有什么时间写博客了.放假了休息一下,就写一篇博客来总结一下最近做项目中出现过的问题吧!!! 首先,在项目中我的起到了什么作用,无非就是把美工(UI设计师)给我们的图显示出来,然后再和服 ...
- NT kernel & System 占用占用80端口
问题: 1 运行'netstat -ano'发现80端口被pid=4的进程占用 2 打开任务管理器,发现pid=4的进程,其实是system进程,其对应的进程描述是NT kernel & sy ...
- VB MSFlexGrid 用法
http://blog.itpub.net/15453304/viewspace-445608/ 问题一,MSFlexGrid 点击一行,显示背景颜色,然后得到行号 首先,右键单击Msflexgrid ...
- Qt入门学习——Qt 5 帮助文档的使用
Qt入门学习——Qt 5 帮助文档的使用 学习图形界面开发,肯定离不开帮助文档的使用,因为它不像 C 语言那样就那么几个函数接口,图形接口的接口可以用海量来形容,常用的我们可能能记住,其它的真的没有必 ...