Automating Custom Icon Assignments in Omnissa Horizon using REST API
Delivering a polished and intuitive user experience is essential. One often-overlooked detail is the assignment of custom icons to published applications, which can enhance usability and improve branding. Thankfully, with the Horizon REST API and a little PowerShell, this process can be fully automated.
In this post, we’ll walk through the essentials of the Horizon REST API and demonstrate how to automatically assign a custom icon to an application pool using a PowerShell script.
Introduction to the Omnissa Horizon REST API
Omnissa Horizon includes a RESTful API interface that allows administrators to programmatically manage the Horizon environment. This includes tasks such as:
-
Authenticating and obtaining access tokens.
-
Querying and managing inventory (e.g., application pools).
-
Uploading and associating application icons.
The API uses standard HTTP methods (GET, POST, etc.) and expects JSON-formatted requests and responses. Authentication is typically done using a bearer token obtained through a login endpoint.
Automating Custom Icon Assignment
The following PowerShell script automates the complete process of:
-
Authenticating to the Horizon REST API.
-
Uploading a custom icon.
-
Fetching the application pool ID by name.
-
Associating the uploaded icon with the specified application.
Here is the annotated PowerShell script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# --- Step 1: Get admin credentials securely --- $cred = Get-Credential $domain = "yourdomain" # --- Step 2: Build login payload --- $loginBody = @{ username = $cred.UserName password = $cred.GetNetworkCredential().Password domain = $domain } | ConvertTo-Json # --- Step 3: API base URL and cert bypass for testing --- $restApiBaseUrl = "https://horizon.domain.com/rest" Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy # --- Step 4: Authenticate and get token --- $tokenResponse = Invoke-RestMethod -Method POST -Uri "$restApiBaseUrl/login" -Body $loginBody -ContentType "application/json" $token = $tokenResponse.access_token $headers = @{ "Authorization" = "Bearer $token" } # --- Step 5: Load and encode icon file --- $iconFilePath = "C:\path\file.png" $iconBytes = [System.IO.File]::ReadAllBytes($iconFilePath) $base64Icon = [System.Convert]::ToBase64String($iconBytes) # --- Step 6: Upload the icon --- $iconBody = @{ data = $base64Icon height = 256 width = 256 } | ConvertTo-Json -Depth 2 $response = Invoke-RestMethod -Method POST -Uri "$restApiBaseUrl/inventory/v1/application-icons" -Headers $headers -Body $iconBody -ContentType "application/json" # --- Step 7: Retrieve the icon ID from the uploaded base64 data --- $iconId = ((Invoke-RestMethod -Method GET -Uri "$restApiBaseUrl/inventory/v1/application-icons/custom-icons" -Headers $headers -ContentType "application/json") | Select-Object data,id | Where-Object {$_.data -eq $base64Icon}).id # --- Step 8: Get application ID by name (e.g., Notepad) --- $appFilterJSON = @{ type = "Equals" name = "name" value = "Notepad" } $appFilterURLEncoded = [System.Web.HttpUtility]::UrlEncode(($appFilterJSON | ConvertTo-Json -Depth 2 -Compress)) $appId = (Invoke-RestMethod -Method GET -Uri "$restApiBaseUrl/inventory/v4/application-pools?filter=$appFilterURLEncoded" -Headers $headers).id # --- Step 9: Associate the custom icon with the application --- $appIconAssocBody = @{ application_pool_ids = @("$appId") icon_id = "$iconId" } | ConvertTo-Json -Depth 2 Invoke-RestMethod -Method POST -Uri "$restApiBaseUrl/inventory/v1/application-pools/action/associate" -Headers $headers -Body $appIconAssocBody -ContentType "application/json" |
Final Thoughts
This automation simplifies the process of maintaining a consistent and visually refined Horizon environment. While the script above is tailored to assign a custom icon to “Notepad”, it can be easily adapted for other applications by changing the value
field in the filter section.
With the Horizon REST API, such administrative tasks can be easily scripted, reducing the chances of error and saving valuable time for IT admins.