Get list of configured VMWare Horizon Client Connections for each user and from each specified Endpoint on a Network

References

PowerShell Gallery | ImportExcel 7.8.4

Overview

This one has a very specific use case. It spawned off a requirement to examine what Horizon connections our users were using, before setting a list of pre-defined defaults which was our requirement. We needed to understand the impact this would have on our users so that we could word our communications accordingly. If users were using client connections outside of our defaults, this would no longer be supported.

This script interrogates prefs.txt for each users from each specified Endpoint and returns their list of server addresses.

How to use
  • Enter a list of device names in the file Endpoints.txt (No Headers are required)
  • Run the script. The output will be stored under the scripts directory. As seen in the example below Export_09082023_1626.

Things to note
  • Requires access to each Endpoints C$ Admin Share. If this is restricted on your network from the account you’re using to run the script, this will not work.
Script
#Automation Get File Version
#Gets a list of hostnames and their specified file version based on the file path configured | Requires access to C$ on specified machines.
#Contact | Josh Woods | joshua@jwblog.uk
#Variables
$Endpoints = Get-Content -Path "$PSScriptRoot\Endpoints.txt"
#Reset Variables
$Count = $null
#Modules
#Excel Module
if (Get-Module -ListAvailable -Name ImportExcel) {
#Import Excel Modules are Installed
Clear-Host
Write-Host "`n"
Write-Host " Import Excel Modules are installed" -ForegroundColor Green
Write-Host "`n"
Start-Sleep -s 2
}
else {
#Install Module
Install-Module -Name ImportExcel -scope CurrentUser -Force
}
#Creating the Output Array
$Array1Output = @()
foreach ($Endpoint in $Endpoints) {
#Test if client is online
$TestConnection = Test-Connection -BufferSize 32 -Count 1 -ComputerName $Endpoint -Quiet
#Count progress
$Count = $Count + 1
#Write Output
Clear-Host
Write-Host "$Count/$($Endpoints.Count)"
if ($TestConnection -eq $True) {
#Write Output
Write-Host "Working on $Endpoint"
#File String
$File = "C:\Users\var_username\AppData\Roaming\VMware\VMware Horizon View Client\prefs.txt"
#Transform File Path Represent each Host
$File = $File.Replace("C:\","\\$($Endpoint)\C$\")
#Remove usernames you don't need scanning
$Usernames = Get-Childitem "\\$Endpoint\C$\Users"
$Usernames = $Usernames.Name
$Usernames = $Usernames | Where-Object { $_ -ne "Temp" }
$Usernames = $Usernames | Where-Object { $_ -ne "Public" }
foreach ($Username in $Usernames) {
#Replace var_username in strong with username
$File = $File.Replace("var_username","$Username")
#Convert to XML
[xml]$XMLServerList = Get-Content -path $File
$ServerList = $XMLServerList.root.recentserver.servername | out-string
#Output result to Array
$Array1 = New-Object PSObject
$Array1 | Add-Member -MemberType NoteProperty -Name 'Endpoint' -Value $Endpoint
$Array1 | Add-Member -MemberType NoteProperty -Name 'Username' -Value $Username
$Array1 | Add-Member -MemberType NoteProperty -Name 'ServerNames' -Value $ServerList
$Array1Output += $Array1
}
}
Write-Host "$Endpoint is Offline" -ForegroundColor Red
}
#Export to Excel
$Array1Output | Export-Excel "$PSScriptRoot\Export_$(Get-Date -Format "ddMMyyyy_HHmm").xlsx"