0

Create Horizon Desktop Pool using PowerCLI

In this blog I will describe how to create a VMware Horizon Desktop Pool using PowerCLI. Before you start you first have to download the VMware.HV.Helper module from https://github.com/vmware/PowerCLI-Example-Scripts/tree/master/Modules/VMware.Hv.Helper.

Usually I create a Horizon Pool using the “Add Desktop Pool” wizard in the Horizon Adminstrator. This will take some time and you have to fill out a lot of information and there is always a possibilty to make a mistake. That is the reason why I user PowerCLI to standardize the creation of new Desktop Pools.

The first step is to get the credentials to logon the Horizon Server: 

#Credentials
$Cred = Get-Credential

Then the global settings of the scripts will be set (like vcenter/datstore etc.):

 

#Global Settings
$HVServer = "<Your Horizon View Connection Server>"
$Vcenter = "<Your vCenter>"
$datacenter = "<Your Datacenter>"
$datastore = "<Your Datsastore>"
$DomainAdmin = "<Your Instant Clone Domain Admin>"
$HostOrCluster = "<Your Cluster>"
$ResourcePool = "<Resourcepool path>"
$NetBiosName = "<Your NETBIOS>"$ParentVM = ""
$ParentVM = "<Name of ParentVM>"
$SnapshotVM = "<Name of Snapshot VM>"

The next step is to define the environments/desktop pools. In this example I created a Production, Test and Proof of Concept Desktop Pool.

#Select Environment
$Environment = "PRODUCTION" # or TEST or PROOFOFCONCEPT

If ($environment -eq "PRODUCTION")
    {
        $PoolName = "PRODUCTION"
        $PoolDisplayName = "PRODUCTION"
        $ProvTime = "UP_FRONT"
        $VmFolder  = "</DATASTORE/FOLDER>"
        $MinimumCount = 1
        $MaximumCount = 5
        $SpareCount = 1
        $NumUnassignedMachinesKeptPoweredOn = 1
        $AdContainer = "OU=PRODUCTION,OU=VIRTUAL DESKTOPS"
    }

If ($environment -eq "TEST")
    {
        $PoolName = "TEST"
        $PoolDisplayName = "TEST"
        $ProvTime = "UP_FRONT"
        $VmFolder  = "</DATASTORE/FOLDER>"
        $MinimumCount = 1
        $MaximumCount = 5
        $SpareCount = 1
        $NumUnassignedMachinesKeptPoweredOn = 1
        $AdContainer = "OU=TEST,OU=VIRTUAL DESKTOPS"
    }	
	
If ($environment -eq "PROOFOFCONCEPT")
    {
        $PoolName = "PROOFOFCONCEPT"
        $PoolDisplayName = "PROOFOFCONCEPT"
        $ProvTime = "UP_FRONT"
        $VmFolder  = "</DATASTORE/FOLDER> "
        $MinimumCount = 1
        $MaximumCount = 5
        $SpareCount = 1
        $NumUnassignedMachinesKeptPoweredOn = 1
        $AdContainer = "OU=PROOFOFCONCEPT,OU=VIRTUAL DESKTOPS"
    }

After this the generic Horizon Settings will be set:

#Generic Horizon Settings
$NamingPattern = "VDI-$($PoolName)-{n:fixed=4}" # for example
$UserAssignment = "FLOATING" # or DEDICATED
$AutomaticAssignment = $true # or $false
$allowUsersToResetMachines = $false # or $true
$AllowMultipleSessionsPerUser = $false # or $true
$deleteOrRefreshMachineAfterLogoff = "REFRESH" # DELETE or NEVER -lof
$RefreshOsDiskAfterLogoff = "NEVER"
$supportedDisplayProtocols = "BLAST","PCOIP"
$renderer3D = "DISABLED"
$enableGRIDvGPUs = $false
$maxNumberOfMonitors = 2
$maxResolutionOfAnyOneMonitor = "WUXGA"
$quality = "NO_CONTROL" #or HIGH LOW MEDIUM
$throttling = "DISABLED" #or AGGRESIVE CONSERVATIVE DISABLED MODERATE
$overrideGlobalSetting = $false # or $true
$UseSeparateDatastoresReplicaAndOSDisks = $false # or $true
$UseViewStorageAccelerator = $false # or $true
$EnableProvisioning = $true # or $false
$NamingMethod = "PATTERN"
$ReclaimVmDiskSpace = $false # or $true
$RedirectWindowsProfile = $false # or $true 
$StopOnProvisioningError = $true # or $true
$StorageOvercommit = "UNBOUNDED"
$UseNativeSnapshots = $false # or $true
$UseSeparateDatastoresPersistentAndOSDisks = $false # or $true
$UseVSAN = $true # or $false
$enableHTMLAccess = $true # or $false
$defaultDisplayProtocol = "BLAST"
$AutomaticLogoffMinutes = 240
$allowUsersToChooseProtocol = 1
$AutomaticLogoffPolicy = "AFTER" #IMMEDIATELY or NEVER
$postsyncscript = ""
$postsyncpara = ""

Now it’s  time to connect to the Horizon Connection Server:

#Connect to Horizon Connection Server
Connect-HVServer -Server $HVServer -Credential $Cred

And finally the Desktop Pool will be created with the New-HVPool command. All the variables I have set before will be used to create the new Desktop Pool.

#Create Pool
New-HVPool -instantclone `
-Datastores $Datastores `
-HostOrCluster $HostOrCluster `
-NamingMethod $NamingMethod `
-NetBiosName $NetBiosName `
-ParentVM $ParentVM `
-PoolName $NewPoolName `
-ResourcePool $ResourcePool `
-SnapshotVM $SnapshotVM `
-UserAssignment $UserAssignment `
-VmFolder $VmFolder `
-AdContainer $AdContainer `
-AutomaticAssignment $AutomaticAssignment `
-datacenter $datacenter `
-DomainAdmin $DomainAdmin `
-Enable $true `
-EnableProvisioning $EnableProvisioning `
-MaximumCount $MaximumCount `
-MinimumCount $MinimumCount `
-NamingPattern $NamingPattern `
-NumUnassignedMachinesKeptPoweredOn $NumUnassignedMachinesKeptPoweredOn `
-PoolDisplayName $PoolDisplayName `
-ProvisioningTime $ProvTime `
-ReclaimVmDiskSpace $ReclaimVmDiskSpace `
-RedirectWindowsProfile $RedirectWindowsProfile `
-SpareCount $SpareCount `
-StopProvisioningOnError $true `
-StorageOvercommit $StorageOvercommit `
-UseNativeSnapshots $UseNativeSnapshots `
-UseSeparateDatastoresReplicaAndOSDisks $UseSeparateDatastoresReplicaAndOSDisks `
-UseVSAN $UseVSAN `
-Vcenter $Vcenter `
-enableHTMLAccess $enableHTMLAccess `
-defaultDisplayProtocol $defaultDisplayProtocol `
-AutomaticLogoffMinutes $AutomaticLogoffMinutes `
-allowUsersToChooseProtocol $allowUsersToChooseProtocol `
-AutomaticLogoffPolicy $AutomaticLogoffPolicy `
-PostSynchronizationScriptParameters $postsyncpara `
-PostSynchronizationScriptName $postsyncscript `

The pool will be created using the settings which were defined in this script.

 

The full script:

#Credentials
$Cred = Get-Credential

#Global Settings
$HVServer = "<Your Horizon View Connection Server>"
$Vcenter = "<Your vCenter>"
$datacenter = "<Your Datacenter>"
$datastore = "<Your Datsastore>"
$DomainAdmin = "<Your Instant Clone Domain Admin>"
$HostOrCluster = "<Your Cluster>"
$ResourcePool = "<Resourcepool path>"
$NetBiosName = "<Your NETBIOS>"$ParentVM = ""
$ParentVM = "<Name of ParentVM>"
$SnapshotVM = "<Name of Snapshot VM>"


#Select Environment
$Environment = "PRODUCTION" # or TEST or PROOFOFCONCEPT

If ($environment -eq "PRODUCTION")
    {
        $PoolName = "PRODUCTION"
        $PoolDisplayName = "PRODUCTION"
        $ProvTime = "UP_FRONT"
        $VmFolder  = "</DATASTORE/FOLDER>"
        $MinimumCount = 1
        $MaximumCount = 5
        $SpareCount = 1
        $NumUnassignedMachinesKeptPoweredOn = 1
        $AdContainer = "OU=PRODUCTION,OU=VIRTUAL DESKTOPS"
    }

If ($environment -eq "TEST")
    {
        $PoolName = "TEST"
        $PoolDisplayName = "TEST"
        $ProvTime = "UP_FRONT"
        $VmFolder  = "</DATASTORE/FOLDER>"
        $MinimumCount = 1
        $MaximumCount = 5
        $SpareCount = 1
        $NumUnassignedMachinesKeptPoweredOn = 1
        $AdContainer = "OU=TEST,OU=VIRTUAL DESKTOPS"
    }	
	
If ($environment -eq "PROOFOFCONCEPT")
    {
        $PoolName = "PROOFOFCONCEPT"
        $PoolDisplayName = "PROOFOFCONCEPT"
        $ProvTime = "UP_FRONT"
        $VmFolder  = "</DATASTORE/FOLDER> "
        $MinimumCount = 1
        $MaximumCount = 5
        $SpareCount = 1
        $NumUnassignedMachinesKeptPoweredOn = 1
        $AdContainer = "OU=PROOFOFCONCEPT,OU=VIRTUAL DESKTOPS"
    }		
	
	
#Generic Horizon Settings
$NamingPattern = "VDI-$($PoolName)-{n:fixed=4}" # for example
$UserAssignment = "FLOATING" # or DEDICATED
$AutomaticAssignment = $true # or $false
$allowUsersToResetMachines = $false # or $true
$AllowMultipleSessionsPerUser = $false # or $true
$deleteOrRefreshMachineAfterLogoff = "REFRESH" # DELETE or NEVER -lof
$RefreshOsDiskAfterLogoff = "NEVER"
$supportedDisplayProtocols = "BLAST","PCOIP"
$renderer3D = "DISABLED"
$enableGRIDvGPUs = $false
$maxNumberOfMonitors = 2
$maxResolutionOfAnyOneMonitor = "WUXGA"
$quality = "NO_CONTROL" #or HIGH LOW MEDIUM
$throttling = "DISABLED" #or AGGRESIVE CONSERVATIVE DISABLED MODERATE
$overrideGlobalSetting = $false # or $true
$UseSeparateDatastoresReplicaAndOSDisks = $false # or $true
$UseViewStorageAccelerator = $false # or $true
$EnableProvisioning = $true # or $false
$NamingMethod = "PATTERN"
$ReclaimVmDiskSpace = $false # or $true
$RedirectWindowsProfile = $false # or $true 
$StopOnProvisioningError = $true # or $true
$StorageOvercommit = "UNBOUNDED"
$UseNativeSnapshots = $false # or $true
$UseSeparateDatastoresPersistentAndOSDisks = $false # or $true
$UseVSAN = $true # or $false
$enableHTMLAccess = $true # or $false
$defaultDisplayProtocol = "BLAST"
$AutomaticLogoffMinutes = 240
$allowUsersToChooseProtocol = 1
$AutomaticLogoffPolicy = "AFTER" #IMMEDIATELY or NEVER
$postsyncscript = ""
$postsyncpara = ""

#Connect to Horizon Connection Server
Connect-HVServer -Server $HVServer -Credential $Cred

#Create Pool
New-HVPool -instantclone `
            -Datastores $Datastores `
            -HostOrCluster $HostOrCluster `
            -NamingMethod $NamingMethod `
            -NetBiosName $NetBiosName `
            -ParentVM $ParentVM `
            -PoolName $NewPoolName `
            -ResourcePool $ResourcePool `
            -SnapshotVM $SnapshotVM `
            -UserAssignment $UserAssignment `
            -VmFolder $VmFolder `
            -AdContainer $AdContainer `
            -AutomaticAssignment $AutomaticAssignment `
            -datacenter $datacenter `
            -DomainAdmin $DomainAdmin `
            -Enable $true `
            -EnableProvisioning $EnableProvisioning `
            -MaximumCount $MaximumCount `
            -MinimumCount $MinimumCount `
            -NamingPattern $NamingPattern `
            -NumUnassignedMachinesKeptPoweredOn $NumUnassignedMachinesKeptPoweredOn `
            -PoolDisplayName $PoolDisplayName `
            -ProvisioningTime $ProvTime `
            -ReclaimVmDiskSpace $ReclaimVmDiskSpace `
            -RedirectWindowsProfile $RedirectWindowsProfile `
            -SpareCount $SpareCount `
            -StopProvisioningOnError $true `
            -StorageOvercommit $StorageOvercommit `
            -UseNativeSnapshots $UseNativeSnapshots `
            -UseSeparateDatastoresReplicaAndOSDisks $UseSeparateDatastoresReplicaAndOSDisks `
            -UseVSAN $UseVSAN `
            -Vcenter $Vcenter `
            -enableHTMLAccess $enableHTMLAccess `
            -defaultDisplayProtocol $defaultDisplayProtocol `
            -AutomaticLogoffMinutes $AutomaticLogoffMinutes `
            -allowUsersToChooseProtocol $allowUsersToChooseProtocol `
            -AutomaticLogoffPolicy $AutomaticLogoffPolicy `
            -PostSynchronizationScriptParameters $postsyncpara `
            -PostSynchronizationScriptName $postsyncscript `

 

Roderik de Block

 

 

 

 

rdeblock

Leave a Reply

Your email address will not be published. Required fields are marked *