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

17 Jan

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

6 Responses to “Automating Desktop Pool creation using PowerCLI – VMware Horizon 7.x”

  1. Snehal April 4, 2019 at 7:02 pm #

    Hi,I did everything in the post, however, I am getting errorGet-VcenterID : vCenter Server not found: [CRPVLX1VCP01.xxxxxxx.xxx], please make sure vCenter is added in Connection ServerAt C:\\Program Files (x86)\\WindowsPowerShell\\Modules\\VMware.Hv.Helper\\VMware.HV.Helper.psm1:4458 char:32+ … virtualCenterID = Get-VcenterID -services $services -vCenter $vCenter+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-VcenterID

  2. Get-Calvus April 24, 2020 at 6:43 pm #

    Where can I find documentation on JSON settings? Obviously I won’t use the same settings as you, so I need to know what syntax I need to use. For example, we use 1680×1050 resolutions. 1680×1050 doesn’t work.

Trackbacks/Pingbacks

  1. Newsletter: March 7, 2020 – Notes from MWhite - March 7, 2020

    […] makes sense of course.  And Horizon is one that people are starting to look at.  So here is an article that will help with automating the rollout of Horizon […]

  2. VMware Horizon 2106: Virtual Desktop Pools – Carl Stalhood - March 9, 2022

    […] you wish to automate the creation of the pool, Aresh Sarkari at Automating Desktop Pool creation using PowerCLI – VMware Horizon 7.x explains New-HVPool -spec 'C:tempDesktopPoolLinkedClone.json' and the contents of the JSON […]

  3. Site Updates – January 2018 – Carl Stalhood - March 9, 2022

    […] In VMware Horizon > Virtual Desktops > Create Pool section, added link to Aresh Sarkari Automating Desktop Pool creation using PowerCLI – VMware Horizon 7.x […]

  4. VMware Horizon 7 – Virtual Desktop Pools – Carl Stalhood - March 9, 2022

    […] 2018 Jan 28 – in Create Pool section, added link to Aresh Sarkari Automating Desktop Pool creation using PowerCLI – VMware Horizon 7.x […]

Leave a Reply

Discover more from AskAresh

Subscribe now to keep reading and get access to the full archive.

Continue reading