henrydenhengst

create a XenDesktop 7.x Delivery Group

May 26th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. # Author: Aaron Parker
  3. # Desc:   Using PowerShell to create a XenDesktop 7.x Delivery Group
  4. # Date:   Aug 23, 2014
  5. # Site:   http://stealthpuppy.com
  6. #
  7. #
  8.  
  9. # Set variables for the target infrastructure
  10. # -
  11. $adminAddress = 'xd71.home.stealthpuppy.com' #The XD Controller we're going to execute against
  12. $xdControllers = 'xd71.home.stealthpuppy.com'
  13.  
  14. # Desktop Group properties
  15. $desktopGroupName = "Windows 8 desktops"
  16. $desktopGroupPublishedName = "Windows 8 desktops"
  17. $desktopGroupDesc = "Windows 8 x86 with Office 2013, Pooled desktops"
  18. $colorDepth = 'TwentyFourBit'
  19. $deliveryType = 'DesktopsOnly'
  20. $desktopKind = 'Shared'
  21. $sessionSupport = "SingleSession" #Also: MultiSession
  22. $functionalLevel = 'L7'
  23. $timeZone = 'AUS Eastern Standard Time'
  24. $offPeakBuffer = 10
  25. $peakBuffer = 10
  26. $assignedGroup = "HOME\Domain Users"
  27.  
  28. #Machine Catalog
  29. $machineCatalogName = "Windows 8 x86"
  30. # -
  31.  
  32. # Change to SilentlyContinue to avoid verbose output
  33. $VerbosePreference = "Continue"
  34.  
  35. # Create the Desktop Group
  36. # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/new-brokerdesktopgroup-xd75.html
  37. If (!(Get-BrokerDesktopGroup -Name $desktopGroupName -ErrorAction SilentlyContinue)) {
  38.     Write-Verbose "Creating new Desktop Group: $desktopGroupName"
  39.     $desktopGroup = New-BrokerDesktopGroup -ErrorAction SilentlyContinue -AdminAddress $adminAddress -Name $desktopGroupName -DesktopKind $desktopKind -DeliveryType $deliveryType -Description $desktopGroupPublishedName -PublishedName $desktopGroupPublishedName  -MinimumFunctionalLevel $functionalLevel -ColorDepth $colorDepth -SessionSupport $sessionSupport -ShutdownDesktopsAfterUse $True -TimeZone $timeZone -InMaintenanceMode $False -IsRemotePC $False -OffPeakBufferSizePercent $offPeakBuffer -PeakBufferSizePercent $peakBuffer -SecureIcaRequired $False -TurnOnAddedMachine $False -OffPeakDisconnectAction Suspend -OffPeakDisconnectTimeout 15 -Scope @()
  40. }
  41.  
  42. # At this point, we have a Desktop Group, but no users or desktops assigned to it, no power management etc.
  43. # Open the properties of the new Desktop Group to see what's missing.
  44.  
  45. # If creation of the desktop group was successful, continue modifying its properties
  46. If ($desktopGroup) {
  47.  
  48.     # Add a machine configuration to the new desktop group; This line adds an existing StoreFront server to the desktop group
  49.     # Where does Input Object 1005 come from?
  50.     # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/add-brokermachineconfiguration-xd75.html
  51.     # Write-Verbose "Adding machine configuration to the Desktop Group: $desktopGroupName"
  52.     # Add-BrokerMachineConfiguration -AdminAddress $adminAddress -DesktopGroup $desktopGroup -InputObject @(1005)
  53.  
  54.     # Add machines to the new desktop group. Uses the number of machines available in the target machine catalog
  55.     # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/add-brokermachinestodesktopgroup-xd75.html
  56.     Write-Verbose "Getting details for the Machine Catalog: $machineCatalogName"
  57.     $machineCatalog = Get-BrokerCatalog -AdminAddress $adminAddress -Name $machineCatalogName
  58.     Write-Verbose "Adding $machineCatalog.UnassignedCount machines to the Desktop Group: $desktopGroupName"
  59.     $machinesCount = Add-BrokerMachinesToDesktopGroup -AdminAddress $adminAddress -Catalog $machineCatalog -Count $machineCatalog.UnassignedCount -DesktopGroup $desktopGroup
  60.  
  61.     # Create a new broker user/group object if it doesn't already exist
  62.     # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/new-brokeruser-xd75.html
  63.     Write-Verbose "Creating user/group object in the broker for $assignedGroup"
  64.     If (!(Get-BrokerUser -AdminAddress $adminAddress -Name $assignedGroup -ErrorAction SilentlyContinue)) {
  65.         $brokerUsers = New-BrokerUser -AdminAddress $adminAddress -Name $assignedGroup
  66.     } Else {
  67.         $brokerUsers = Get-BrokerUser -AdminAddress $adminAddress -Name $assignedGroup
  68.     }
  69.  
  70.     # Create an entitlement policy for the new desktop group. Assigned users to the desktop group
  71.     # First check that we have an entitlement name available. Increment until we do.
  72.     $Num = 1
  73.     Do {
  74.         # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/test-brokerentitlementpolicyrulenameavailable-xd75.html
  75.         $Test = Test-BrokerEntitlementPolicyRuleNameAvailable -AdminAddress $adminAddress -Name @($desktopGroupName + "_" + $Num.ToString()) -ErrorAction SilentlyContinue
  76.         If ($Test.Available -eq $False) { $Num = $Num + 1 }
  77.     } While ($Test.Available -eq $False)
  78.     #http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/new-brokerentitlementpolicyrule-xd75.html
  79.     Write-Verbose "Assigning $brokerUsers.Name to Desktop Catalog: $machineCatalogName"
  80.     $EntPolicyRule = New-BrokerEntitlementPolicyRule -AdminAddress $adminAddress  -Name ($desktopGroupName + "_" + $Num.ToString()) -IncludedUsers $brokerUsers -DesktopGroupUid $desktopGroup.Uid -Enabled $True -IncludedUserFilterEnabled $False
  81.  
  82.     # Check whether access rules exist and then create rules for direct access and via Access Gateway
  83.     # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/new-brokeraccesspolicyrule-xd75.html
  84.     $accessPolicyRule = $desktopGroupName + "_Direct"
  85.     If (Test-BrokerAccessPolicyRuleNameAvailable -AdminAddress $adminAddress -Name @($accessPolicyRule) -ErrorAction SilentlyContinue) {
  86.         Write-Verbose "Allowing direct access rule to the Desktop Catalog: $machineCatalogName"
  87.         New-BrokerAccessPolicyRule -AdminAddress $adminAddress -Name $accessPolicyRule  -IncludedUsers @($brokerUsers.Name) -AllowedConnections 'NotViaAG' -AllowedProtocols @('HDX','RDP') -AllowRestart $True -DesktopGroupUid $desktopGroup.Uid -Enabled $True -IncludedSmartAccessFilterEnabled $True -IncludedUserFilterEnabled $True
  88.     } Else {
  89.         Write-Error "Failed to add direct access rule $accessPolicyRule. It already exists."
  90.     }
  91.     $accessPolicyRule = $desktopGroupName + "_AG"
  92.     If (Test-BrokerAccessPolicyRuleNameAvailable -AdminAddress $adminAddress -Name @($accessPolicyRule) -ErrorAction SilentlyContinue) {
  93.         Write-Verbose "Allowing access via Access Gateway rule to the Desktop Catalog: $machineCatalogName"
  94.         New-BrokerAccessPolicyRule -AdminAddress $adminAddress -Name $accessPolicyRule -IncludedUsers @($brokerUsers.Name) -AllowedConnections 'ViaAG' -AllowedProtocols @('HDX','RDP') -AllowRestart $True -DesktopGroupUid $desktopGroup.Uid -Enabled $True -IncludedSmartAccessFilterEnabled $True -IncludedSmartAccessTags @() -IncludedUserFilterEnabled $True
  95.     } Else {
  96.         Write-Error "Failed to add Access Gateway rule $accessPolicyRule. It already exists."
  97.     }
  98.  
  99.     # Create weekday and weekend access rules
  100.     # http://support.citrix.com/proddocs/topic/citrix-broker-admin-v2-xd75/new-brokerpowertimescheme-xd75.html
  101.     $powerTimeScheme = "Windows 8 Pooled Desktop_Weekdays"
  102.     If (Test-BrokerPowerTimeSchemeNameAvailable -AdminAddress $adminAddress -Name @($powerTimeScheme) -ErrorAction SilentlyContinue) {
  103.         Write-Verbose "Adding new power scheme $powerTimeScheme"
  104.         New-BrokerPowerTimeScheme -AdminAddress $adminAddress -DisplayName 'Weekdays' -Name $powerTimeScheme -DaysOfWeek 'Weekdays' -DesktopGroupUid $desktopGroup.Uid -PeakHours @($False,$False,$False,$False,$False,$False,$False,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$False,$False,$False,$False,$False) -PoolSize @(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0)
  105.     } Else {
  106.         Write-Error "Failed to add power scheme rule $powerTimeScheme. It already exists."
  107.     }
  108.     $powerTimeScheme = "Windows 8 Pooled Desktop_Weekend"
  109.     If (Test-BrokerPowerTimeSchemeNameAvailable -AdminAddress $adminAddress -Name @($powerTimeScheme) -ErrorAction SilentlyContinue) {
  110.         Write-Verbose "Adding new power scheme $powerTimeScheme"
  111.         New-BrokerPowerTimeScheme -AdminAddress $adminAddress -DisplayName 'Weekend' -Name $powerTimeScheme -DaysOfWeek 'Weekend' -DesktopGroupUid $desktopGroup.Uid -PeakHours @($False,$False,$False,$False,$False,$False,$False,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$False,$False,$False,$False,$False) -PoolSize @(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
  112.     } Else {
  113.         Write-Error "Failed to add power scheme rule $powerTimeScheme. It already exists."
  114.     }
  115.  
  116. } #End If DesktopGroup
Add Comment
Please, Sign In to add comment