About Me

My photo
This blog has been created to share technical information, interesting innovations that I notice on daily basis and Architectural/Consulting overview of various technologies. My areas of interest, on which I would be blogging, are VMware, Microsoft and Citrix Technologies. I hope you will enjoy this blog and share your experience with me.

Automating Desktop Pool creation using PowerCLI – VMware Horizon 7.x

The Desktop Pool Creation using PowerCLI and JSON file is by far the most powerful and advance way of creating desktop pools in Horizon 7.x in a automated way.

Before you begin with the script and JSON file make sure you have read this blog post “Automating VMware Horizon 7 with VMware PowerCLI 6.5” by Graeme Gordon it explains step by step how to prepare machine and execute the PowerCLI.

The following is the script (Save as desktoppool.ps1) you will need to execute this script for invoking the desktop pool creation using the advanced functions of the module - New-HVPool -spec 'path to InstantClone.json file'

PowerCLI Script for Desktop Pool:

################################################################################
# Create a Linked Clone Desktop Pool in Horizon using PowerCLI and Defining parameters in JSON
################################################################################

#region variables
################################################################################
#                                    Variables                                 #
################################################################################
$cs = 'cs1-1.domain.com' #Horizon Connection Server (CS)
$csUser= 'aresh' #User account to connect to CS make sure you have necessary permissions
$csPassword = 'abc1234' #Password for user to connect to Connection Server
$csDomain = 'domain' #Domain for user to connect to Connection Server
#endregion variables

#region initialize
################################################################################
#                                    Initialize                                #
################################################################################
# --- Initialize All PowerCLI Modules ---
#Importing the Hv.Helper Module for Horizon
Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module

# Connect to Horizon Connection Server API Service
$hvServer1 = Connect-HVServer -Server $cs -User $csUser -Password $csPassword -Domain $csDomain

# --- Display Available Methods for interacting with the API Service API Service ---
$Services1= $hvServer1.ExtensionData

#endregion initialize

#region logic
################################################################################
#                                Main-Logic                                    #
################################################################################

# --- Create the pool ---
New-HVPool -spec 'C:\temp\DesktopPool\LinkedClone.json'


# --- Disconnnect from Horizon API Service ---
Disconnect-HVServer -Server $cs -Confirm
#endregion logic


Now let’s take a look at the JSON file for Linked Clone Desktops as all the advanced parameters for the desktop pool creation are defined here. The effort of entering the parameters needs to be performed once usually 70% of parameters are standard across all the pools. During the new pool creation only 5-7 parameters needs to change and rest can remain as-is

Note - I have entered parameters based on my requirements feel free to modify the values. (Copy/paste the below into a JSON editor to make sure the editing is in correct format. Save the file as LinkedClone.json):

Linked Clone JSON – (All parameters should be configured through JSON)

{
     "Base": {
         "Name": "Aresh-Test",
         "DisplayName": "Aresh linkedclone pool",
         "AccessGroup": "Root",
         "Description": "Created linked clone pool from PowerCLI"
     },
     "DesktopSettings": {
         "enabled": true,
         "deleting": false,
         "connectionServerRestrictions": null,
         "logoffSettings": {
             "powerPolicy": "TAKE_NO_POWER_ACTION",
             "automaticLogoffPolicy": "AFTER",
             "automaticLogoffMinutes": 4320,
             "allowUsersToResetMachines": true,
             "allowMultipleSessionsPerUser": false,
             "deleteOrRefreshMachineAfterLogoff": "REFRESH",
             "refreshOsDiskAfterLogoff": "NEVER",
             "refreshPeriodDaysForReplicaOsDisk": 5,
             "refreshThresholdPercentageForReplicaOsDisk": 10
         },
         "displayProtocolSettings": {
             "supportedDisplayProtocols": ["RDP",
             "PCOIP",
             "BLAST"],
             "defaultDisplayProtocol": "BLAST",
             "allowUsersToChooseProtocol": true,
             "pcoipDisplaySettings": {
                 "renderer3D": "DISABLED",
                 "enableGRIDvGPUs": false,
                 "vRamSizeMB": 96,
                 "maxNumberOfMonitors": 2,
                 "maxResolutionOfAnyOneMonitor": "WQXGA"
             },
             "enableHTMLAccess": true
         },
         "flashSettings": {
             "quality": "NO_CONTROL",
             "throttling": "DISABLED"
         },
         "mirageConfigurationOverrides": {
             "overrideGlobalSetting": false,
             "enabled": false,
             "url": null
         }
     },
     "Type": "AUTOMATED",
     "AutomatedDesktopSpec": {
         "ProvisioningType": "VIEW_COMPOSER",
         "VirtualCenter": "10.x.x.x",
         "UserAssignment": {
             "UserAssignment": "FLOATING",
             "AutomaticAssignment": true
         },
         "VmNamingSpec": {
             "NamingMethod": "PATTERN",
             "PatternNamingSettings": {
                 "NamingPattern": "HZ-W10-{n:fixed=3}",
                 "MaxNumberOfMachines": 1,
                 "NumberOfSpareMachines": 1,
                 "ProvisioningTime": "UP_FRONT",
                 "MinNumberOfMachines": null
             },
             "SpecificNamingSpec": null
         },
         "VirtualCenterProvisioningSettings": {
             "EnableProvisioning": true,
             "StopProvisioningOnError": true,
             "MinReadyVMsOnVComposerMaintenance": 0,
             "VirtualCenterProvisioningData": {
                 "Template": null,
                 "ParentVm": "W101607-STD1",
                 "Snapshot": "v1",
                 "Datacenter": "vRack-Datacenter",
                 "VmFolder": "GM_MasterImages",
                 "HostOrCluster": "vcore1c2-0-cluster",
                 "ResourcePool": "vcore1c2-0-cluster"
             },
             "VirtualCenterStorageSettings": {
                 "Datastores": [{
                     "Datastore": "vsanDatastore",
                     "StorageOvercommit": "UNBOUNDED"
                 }],
                 "UseVSan": true,
                 "ViewComposerStorageSettings": {
                     "UseSeparateDatastoresReplicaAndOSDisks": false,
                     "ReplicaDiskDatastore": null,
                     "UseNativeSnapshots": false,
                     "SpaceReclamationSettings": {
                         "ReclaimVmDiskSpace": false,
                         "ReclamationThresholdGB": null,
                         "BlackoutTimes": null
                     },
                     "PersistentDiskSettings": {
                         "RedirectWindowsProfile": false,
                         "UseSeparateDatastoresPersistentAndOSDisks": null,
                         "PersistentDiskDatastores": null,
                         "DiskSizeMB": null,
                         "DiskDriveLetter": null
                     },
                     "NonPersistentDiskSettings": {
                         "RedirectDisposableFiles": false,
                         "DiskSizeMB": null,
                         "DiskDriveLetter": null
                     }
                 },
                 "ViewStorageAcceleratorSettings": {
                     "useViewStorageAccelerator": true,
                     "viewComposerDiskTypes": "OS_DISKS",
                     "regenerateViewStorageAcceleratorDays": 7,
                     "BlackoutTimes": null
                 }
             },
             "VirtualCenterNetworkingSettings": {
                 "Nics": [{
                     "Nic": "nicName",
                     "NetworkLabelAssignmentSpecs": [{
                         "Enabled": false,
                         "networkLabel": null,
                         "maxLabelType": null,
                         "maxLabel": null
                     }]
                 }]
             }
         },
         "VirtualCenterManagedCommonSettings": {
             "TransparentPageSharingScope": "VM"
         },
         "CustomizationSettings": {
             "CustomizationType": "QUICK_PREP",
             "DomainAdministrator": "viewcomposer-svc",
             "AdContainer": "OU=HZ-AWF,OU=BLR,OU=Computers",
             "ReusePreExistingAccounts": false,
             "NoCustomizationSettings": null,
             "SysprepCustomizationSettings": {
                 "customizationSpec": null
             },
             "QuickprepCustomizationSettings": {
                 "PowerOffScriptName": null,
                 "PowerOffScriptParameters": null,
                 "PostSynchronizationScriptName": null,
                 "PostSynchronizationScriptParameters": null
             },
             "CloneprepCustomizationSettings": null
         }
     },
     "ManualDesktopSpec": null,
     "RdsDesktopSpec": null,
     "GlobalEntitlementData": null,
     "NetBiosName": "domain"
}

The parameters are self explanatory they are the exact same shown in the Horizon Administrator UI during Desktop Pool Creation. If you need any additional information on the parameters refer to the VMware View API explorer for more details.

I hope you will find this script and method useful in Automating the Desktop Pool Creation in Horizon. If you have further questions leave a comment or DM on twitter.

Thanks,
Aresh Sarkari

No comments:

My Blog List