33
POWERSHELL IN CITRIX XENDESKTOP 5 Jonathan Medd

PowerShell in XenDesktop 5

Embed Size (px)

DESCRIPTION

PowerShell in XenDesktop 5

Citation preview

Page 1: PowerShell in XenDesktop 5

POWERSHELL IN CITRIX XENDESKTOP 5

Jonathan Medd

Page 2: PowerShell in XenDesktop 5

What is Citrix XenDesktop?

Page 3: PowerShell in XenDesktop 5

What is Citrix XenDesktop?

Page 4: PowerShell in XenDesktop 5

How Does It Work?

Page 5: PowerShell in XenDesktop 5

XenDesktop 5 and PowerShell

XenDesktop Management built on top of PowerShell

Desktop Studio Management tool issues PowerShell commands behind the scenes

Replaces the MFCOM scripting of previous versions (Same story in XenApp 6)

Page 6: PowerShell in XenDesktop 5

Pre-Requisites for Management Workstation

Install Desktop Studio on an admin workstation

http://support.citrix.com/article/CTX127527

Page 7: PowerShell in XenDesktop 5

Consists of….PSSnapins and Providers

Page 8: PowerShell in XenDesktop 5

Consists of….PSSnapins and Providers

Total of 330 Cmdlets across all PSSnapins

http://support.citrix.com/static/kc/CTX127254/help/index.htm

Page 9: PowerShell in XenDesktop 5

Hypervisor Connections and Hosting Units Provider

Supports the major hypervisors: Citrix XenServer VMware vSphere Microsoft Hyper-V

Page 10: PowerShell in XenDesktop 5

Hypervisor Connections and Hosting Units Provider

Page 11: PowerShell in XenDesktop 5

Hypervisor Connections and Hosting Units Provider

Manage with standard PowerShell cmdlets: Get-Childitem, Get-Item New-Item Set-Item Rename-Item Remove-Item

Page 12: PowerShell in XenDesktop 5

Hypervisor Connections and Hosting Units Provider

Give slightly more cmdlet feel with these functions: Function Get-HypervisorConnection

{Get-ChildItem xdhyp:\Connections} Function Get-HostingUnit {Get-Childitem

xdhyp:\HostingUnits}

Page 13: PowerShell in XenDesktop 5

Demo: Create a Hypervisor Connection and a Hosting Unit $HypConn = New-Item -Path xdhyp:\Connections -Name

vCenter01 -HypervisorAddress http://vcenter01.sunnydale.local/sdk -UserName XenDesktop -Password Password01 -ConnectionType vCenter –Persist

New-Item -Path xdhyp:\HostingUnits -Name pESX02 -HypervisorConnectionName vCenter01 -RootPath XDHyp:\Connections\vCenter01\HQ.datacenter\Physical.folder\pesx02.sunnydale.local.computeresource -NetworkPath "XDHyp:\Connections\vCenter01\HQ.datacenter\Physical.folder\pesx02.sunnydale.local.computeresource\VM Network 20.network" -StoragePath "XDHyp:\Connections\vCenter01\HQ.datacenter\Physical.folder\pesx02.sunnydale.local.computeresource\pESX02_Local.storage“

New-BrokerHypervisorConnection -HypHypervisorConnectionUid $HypConn.HypervisorConnectionUid

Page 14: PowerShell in XenDesktop 5

Demo: Create a Hypervisor Connection and a Hosting Unit

Page 15: PowerShell in XenDesktop 5

All actions in Desktop Studio Run PowerShell Under the Hood

Page 16: PowerShell in XenDesktop 5

Demo: All actions in Desktop Studio Run PowerShell Under the Hood

• Remove Hypervisor Connection

Page 17: PowerShell in XenDesktop 5

Managing Administrators

• New-BrokerAdministrator -BrokerAdmin $False -Enabled $True -FullAdmin $True -Name 'SUNNYDALE\XenDesktopAdmins' -ProvisioningAdmin $False -ReadOnly $False -AdminAddress 'DDC01.sunnydale.local:80‘

• Set-BrokerAdministrator -Name 'SUNNYDALE\XenDesktopAdmins' -BrokerAdmin $False -Enabled $False -FullAdmin $True -ProvisioningAdmin $False -ReadOnly $False -AdminAddress 'DDC01.sunnydale.local:80'

Page 18: PowerShell in XenDesktop 5

Demo: Managing Administrators

Page 19: PowerShell in XenDesktop 5

Create a Catalog$CatalogName = "Windows 7 Catalog“ #Name of the catalog that will be created$CatalogDescription = "Windows 7 MCS Catalog" #Description given to the catalog$DeviceNamingScheme = "Win7-#" #Naming scheme for the MCS-created VMs$DeviceNamingSchemeType = "Numeric" #Naming scheme type for the MCS-created VMs$DeviceOU = "OU=Workstations,DC=sunnydale,DC=local" #Active Directory OU where the MCS-created VMs will be placed$DeviceDomain = "sunnydale.local" #Active Directory Domain where the MCS-created VMs will be managed$MasterVMName = "Win7Image" #Name of the "Master VM" that will be used with MCS$NumDeviceAccounts = 1 #Create 1 VM with MCS using the naming scheme defined above$DeviceStartIndex = 1 #VM names should start with an index of 1$VMCpuCount = 1 #Two vcpu's for each MCS-created VM$VMMemoryMB = 1024 #1GB ram for each MCS-created VM$HostUnitName = "pESX02" #vSphere "host" as listed in the Hosts node of the Desktop Studio Console$DDCAddress = “DDC01.sunnydale.local:80" #DDC the cmdlets will connect to

http://blogs.citrix.com/2011/03/24/xendesktop-5-powershell-sdk-primer-part-3-creating-pooled-catalogs-that-leverage-machine-creation-services/

Page 20: PowerShell in XenDesktop 5

Create a Catalog

During Catalog creation you will see the below in Desktop Studio until Catalog has been created

Page 21: PowerShell in XenDesktop 5

Create a Catalog

#Create the catalog container$Catalog = New-BrokerCatalog -AllocationType 'Random' -CatalogKind 'SingleImage' -Name $CatalogName -Description $CatalogDescription -PvsForVM @() -AdminAddress $DDCAddress#Create an identity pool to store the AD computer account info for this catalog.#We are giving the identity pool the same name as the catalog to keep better track$IdentityPool = New-AcctIdentityPool -IdentityPoolName $CatalogName -NamingScheme $DeviceNamingScheme -NamingSchemeType $DeviceNamingSchemeType -OU $DeviceOU -Domain $DeviceDomain -AllowUnicode -AdminAddress $DDCAddress$IdentityPool

Page 22: PowerShell in XenDesktop 5

Create a Catalog

#Get reference to the broker service group$BrokerServiceGroup = Get-ConfigServiceGroup -ServiceType "Broker" -AdminAddress $DDCAddress$BrokerServiceGroup

#Add metadata to the broker service group to tie the catalog with the identity pool it is using$MetadataPropertyName = "Citrix_DesktopStudio_BrokerCatalogIdentityPoolReferencePrefix_" + $Catalog.Uid$MetadataPropertyValue = $IdentityPool.IdentityPoolUid

$NewMetadata = Add-ConfigServiceGroupMetadata -ServiceGroupUid $BrokerServiceGroup.ServiceGroupUid -Property $MetadataPropertyName -Value $MetadataPropertyValue -AdminAddress $DDCAddress

Page 23: PowerShell in XenDesktop 5

Create a Catalog

#Get reference to the hosting unit and hypervisor connection it uses$HostUnitPath = 'xdhyp:\hostingunits\' + $HostUnitName$HostUnit = Get-Item -Path $HostUnitPath

$HypConnection = Get-BrokerHypervisorConnection -Name $HostUnit.HypervisorConnection.HypervisorConnectionName -AdminAddress $DDCAddress

Page 24: PowerShell in XenDesktop 5

Create a Catalog

#Create a snapshot of the master VM image$SnapshotName = "Citrix_XD_" + $CatalogName$MasterVMPath = "XDHyp:\hostingunits\" + $HostUnit.HostingUnitName + "\" + $MasterVMName + ".vm"$Snapshot = New-HypVMSnapshot -SnapshotName $SnapshotName -LiteralPath $MasterVMPath -AdminAddress $DDCAddress

Page 25: PowerShell in XenDesktop 5

Create a Catalog

#Create a provisioning scheme that defines the details of the MCS cloned VMs.#This process creates a copy of the snapshot and can take several minutes to complete.#Note: New-ProvScheme returns a GUID that represents the TaskID for the copy task.$ProvSchemeName = $CatalogName + "_" + $HostUnit.HostingUnitName$SnapshotPath = $MasterVMPath + "\" + $SnapshotName + ".snapshot“

$ProvSchemeTask = New-ProvScheme -ProvisioningSchemeName $ProvSchemeName -HostingUnitName $HostUnit.HostingUnitName -IdentityPoolName $IdentityPool.IdentityPoolName -VMCpuCount $VMCpuCount -VMMemoryMB $VMMemoryMB -CleanOnBoot -MasterImageVM $SnapshotPath -RunAsynchronously -AdminAddress $DDCAddress

Page 26: PowerShell in XenDesktop 5

Nearly there!

Page 27: PowerShell in XenDesktop 5

Create a Catalog

#Update the catalog with what provisioning scheme and hosting unit it is using$ProvScheme = Get-ProvScheme -ProvisioningSchemeName $ProvSchemeName -AdminAddress $DDCAddress$PvsForVM = $ProvScheme.ProvisioningSchemeUid.ToString() + ":" + $ProvScheme.HostingUnitUid.ToString()Set-BrokerCatalog -Name $strCatalogName -PvsForVM $strPvsForVM -AdminAddress $strDDCAddress

Page 28: PowerShell in XenDesktop 5

Create a Catalog

#Create machine accounts in Active Directory from info stored in the identity pool.#After running this command, the machine accounts should be visible within the Active Directory "Users and Computers" snap-in.$Accounts = New-AcctADAccount -IdentityPoolName $IdentityPool.IdentityPoolName -Count $NumDeviceAccounts -StartCount $DeviceStartIndex -AdminAddress $DDCAddress

Page 29: PowerShell in XenDesktop 5

Create a Catalog

#Associate controllers (DDC Servers) to the provisioning scheme.$ProvScheme = Add-ProvSchemeControllerAddress -ProvisioningSchemeName $ProvScheme.ProvisioningSchemeName -ControllerAddress $DDCAddress -AdminAddress $DDCAddress

#Create virtual desktop VMs from the info specified by the provisioning scheme. After executing this command, the VMs will show up in the hypervisor.$ProvVMTask = New-ProvVM -ProvisioningSchemeName $ProvScheme.ProvisioningSchemeName -ADAccountName $Accounts.SuccessfulAccounts -RunAsynchronously -AdminAddress $DDCAddress

Page 30: PowerShell in XenDesktop 5

Create a Catalog#Loop though the newly provisioned VMs, "lock" them, and add them to the catalog$ProvVMs = Get-ProvVM -ProvisioningSchemeName $ProvScheme.ProvisioningSchemeName -AdminAddress $strDDCAddressif ($ProvVMs -ne $null) { foreach ($ProvVM in $ProvVMs) {

#Lock VM in the provisioning scheme with a tag called "Brokered" (so it cannot be removed without being unlocked first) $LockVM = Lock-ProvVM -ProvisioningSchemeName $ProvScheme.ProvisioningSchemeName -VMID $ProvVM.VMId -Tag "Brokered" -AdminAddress $DDCAddress

#Add VM to the catalog created above $BrokerMachine = New-BrokerMachine -CatalogUid $Catalog.Uid -HostedMachineId $ProvVM.VMId -HypervisorConnectionUid $HypConnection.Uid -MachineName $ProvVM.ADAccountSid -AdminAddress $DDCAddress

if ($BrokerMachine -ne $null){ Write-Host "Successfully added" $ProvVM.ADAccountName "to the"

$Catalog.Name "catalog..."}else{

Write-Host "ERROR: Could not add" $ProvVM.ADAccountName "to the" $Catalog.Name "catalog..."

} }}

Page 31: PowerShell in XenDesktop 5

Create a Catalog – Finished!

Page 32: PowerShell in XenDesktop 5

Bonus: Automate the DDC Install

http://www.jonathanmedd.net/2012/06/automating-the-install-of-xendesktop-ddc-with-powershell.html