One of my New Year’s resolutions is to blog more. Recently, I have built some PowerShell scripts to perform several tasks for me at work using the Omnissa Horizon REST API. It seems there aren’t a ton of blogs out there on this sort of thing, so here goes!
As always, NEVER use these commands in production without testing. Despite the fact this script works for me in my lab and in production, past success doesn’t guarantee future results!
Now that we have that out of the way, on to the fun stuff.
This script had a few goals in mind:
- Automate the creation of a new VDI pool that is identical to another VDI pool other than the following
- Creates a new POOL ID (required)
- Allows the administrator to enter the pool “name” that you want to clone
- Allows the administrator to enter the pool “name” that you want to create
- Allows the administrator to enter the pool “naming pattern” (required as it must be different than the pool you are cloning)
- The script allows for skipping a certificate check if you are using an invalid cert (remarked by default)
- Most everything else will be identical including:
- Active Directory OU
- Max number of machines
- Min number of machines
- Number of spare machines
- Display Protocol settings/defaults
- Session settings/defaults
- Parent Image and Snapshot
- Things that do not come over
- Pool Entitlements
First of all, a little bit about my environment. Our desktop image is Windows 11 23H2. We have two environments in my lab. One is VMware Cloud Foundation 9.0.1 (vSphere 9, vCenter 9) and an NFS datastore. The other is vSphere 8 with an iSCSI datastore. I have one HP DL360 Gen9 with 512GB RAM and one HP DL360 Gen10 with 384GB RAM. Both systems have nested ESXi hosts that comprise my VCF environment. I also have some Intel Gen10 NUC’s for my vSphere 8 environment. The vSphere and VCF environment is licensed using my VMUG Advantage. Learn more about VMUG Advantage here.
Additionally, my Horizon environment is licensed with my membership as an Omnissa Tech Insider. For more information on that program, go to Join the Omnissa Tech Insider Program: Help shape the future of End-User Computing – Community Updates – Omnissa Community. Applications are currently closed, but watch out for future announcements!
The script is broken down in to several parts:
- Define variables for pool clone operations
- Validate if you have a valid API token (enumerate a list of connection servers as a test)
- Enter credentials if you do not
- I blogged previously on logging in to the REST API HERE
- Connect to the /rest/login endpoint with your credentials
- Get a list of all pools
- Extract the pool you want to clone from the list along with all settings
- Clone the pool into a new powershell object
- Within that new pool object
- Create a new ID
- Replace with new pool name
- Replace with new pool display name
- Replace pool naming pattern
- Display some key pool settings to the admin and give them an opportunity to quit or continue
- Using the new pool settings, export to a JSON and POST to /rest/inventory/v12/desktop-pools to create the new pool.
When you run the PowerShell script, feel free to type NO to stop the script from completing. You can look at the $newPool object and look at the objects underneath.
PS C:\> $newpool.pattern_naming_settings
naming_pattern : WIN11-B{n:fixed=2}
provisioning_time : ON_DEMAND
max_number_of_machines : 3
min_number_of_machines : 1
number_of_spare_machines : 1
or
PS C:\> $newpool.provisioning_settings
min_ready_vms_on_vcomposer_maintenance : 0
add_virtual_tpm : True
parent_vm_id : vm-2013
base_snapshot_id : snapshot-2014
datacenter_id : datacenter-3
vm_folder_id : group-v4
host_or_cluster_id : domain-c10
resource_pool_id : resgroup-11
resource_pool_path : /VCF01-M01-DC01/host/VCF01-M01-DC01-CL01/Resources
snapshot_path : /2025-12-09 – post migrate to VCF
parent_vm_path : /VCF01-M01-DC01/vm/W11-23H2-1
vm_folder_path : /VCF01-M01-DC01/vm/WIN11
datacenter_name : VCF01-M01-DC01
host_or_cluster_path : /VCF01-M01-DC01/host/VCF01-M01-DC01-CL01
The $newpool variable contains everything you would have posted into the REST API endpoint for pool creation. Run the pool again and you will see how it works!
I have found that a simple pool clone operation can take as little as one minute for it to become fully available.
Feel free to modify this script as you wish. Let’s say you would like to allow for a customizable “max_number_of_machines” object. All you would need to do is to replace the $newpool.pattern_naming_settings.max_number_of_machines object with a variable of choice, perhaps by using Read-Host if you like. Make sure the value is an integer, and run the POST command to create the new pool.
In a future blog, I will share a script that uses some of these methods to modify pool settings like max desktops, min desktops, spare desktops, or to disable/enable provisioning, or disable/enable a pool.
Feel free to download this PowerShell script here. Enjoy!