A while ago I was working on a very very old VMware View environment. Yes, you’ve read this correctly, a VMware View environment. This is even from before the product was officially called “VMware Horizon View” back in 2015.
So, the subject I was working on for the customer, but also for us since we manage it, was that we needed to know who got what session at what time of the day, and how many users logged in daily. This information would also be used for troubleshooting, since the environment wasn’t that up to date anymore, as you can probably imagine.
So, how did we tackle this? Well the VMware View Administrator console was not really up for the task, since you can only check “Current” or “Highest” number of sessions, but nothing with names, timestamps or anything like that.
What else can we use to get this information? Well, the only thing that I actually found that worked with this ancient environment were my trusted good ol’ PowerCLI modules! The VMware View PowerCLI plugin (VMware.View.Broker) for that matter. These are HARD to find for this old environment! I actually couldn’t find any downloads anymore at all, anywhere! Luckily the plugin was still inside the installation folder on the VMware View Connection Server. I did manage to save the add-snapin.ps1 and uninstall-snapin.ps1 files for this module. But if you don’t have the installation files that include the “.dll’s” you need, you don’t have any use for this (if you do want these, just let me know!).
Let’s suppose you have the View PowerCLI modules installed, like me, how do we get the information we need? Well let’s first have a look at the commands we have available in the plugin. You can do this by executing the following piece of code:
Get-Command | ?{$_.PSSnapin.name -eq "VMware.View.Broker"}
CommandType Name Definition
----------- ---- ----------
Cmdlet Add-AutomaticLinkedClonePool Add-AutomaticLinkedClonePool...
Cmdlet Add-AutomaticPool Add-AutomaticPool [-Pool_id ...
Cmdlet Add-ManualPool Add-ManualPool [-Pool_id <St...
Cmdlet Add-ManualUnmanagedPool Add-ManualUnmanagedPool [-Po...
Cmdlet Add-PoolEntitlement Add-PoolEntitlement [-Pool_i...
Cmdlet Add-TerminalServerPool Add-TerminalServerPool [-Poo...
Cmdlet Add-TransferServer Add-TransferServer [-Vc_id <...
Cmdlet Add-ViewVC Add-ViewVC [-ServerName <Str...
Cmdlet Export-NetworkLabelSpecForFu... Export-NetworkLabelSpecForFu...
Cmdlet Export-NetworkLabelSpecForLi... Export-NetworkLabelSpecForLi...
Cmdlet Get-ComposerDomain Get-ComposerDomain [-Vc_id <...
Cmdlet Get-ConnectionBroker Get-ConnectionBroker [[-Brok...
Cmdlet Get-DesktopPhysicalMachine Get-DesktopPhysicalMachine [...
Cmdlet Get-DesktopVM Get-DesktopVM [-Vc_id <Strin...
Cmdlet Get-EventReport Get-EventReport [-ViewName <...
Cmdlet Get-EventReportList Get-EventReportList [-Verbos...
Cmdlet Get-GlobalSetting Get-GlobalSetting [-Verbose]...
Cmdlet Get-License Get-License [-Verbose] [-Deb...
Cmdlet Get-LocalSession Get-LocalSession [-Pool_id <...
Cmdlet Get-Monitor Get-Monitor [-Monitor <Strin...
Cmdlet Get-Pool Get-Pool [-Pool_id <String[]...
Cmdlet Get-PoolEntitlement Get-PoolEntitlement [[-Pool_...
Cmdlet Get-ProfileDisk Get-ProfileDisk [-Name <Stri...
Cmdlet Get-RemoteSession Get-RemoteSession [-Username...
Cmdlet Get-TerminalServer Get-TerminalServer [-Display...
Cmdlet Get-TransferPackage Get-TransferPackage [-Packag...
Cmdlet Get-TransferServer Get-TransferServer [-Path <S...
Cmdlet Get-TransferServerState Get-TransferServerState [-Ts...
Cmdlet Get-User Get-User [-IncludeUser] [-In...
Cmdlet Get-ViewVC Get-ViewVC [-DisplayName <St...
Cmdlet New-TransferPackage New-TransferPackage [-Vc_id ...
Cmdlet Remove-Pool Remove-Pool [-Pool_id <Strin...
Cmdlet Remove-PoolEntitlement Remove-PoolEntitlement [-Poo...
Cmdlet Remove-TransferPackage Remove-TransferPackage [[-Pa...
Cmdlet Remove-TransferServer Remove-TransferServer [[-Ts_...
Cmdlet Remove-UserOwnership Remove-UserOwnership [[-Mach...
Cmdlet Remove-ViewVC Remove-ViewVC [-Vc_id <Strin...
Cmdlet Send-LinkedCloneRebalance Send-LinkedCloneRebalance [-...
Cmdlet Send-LinkedCloneRecompose Send-LinkedCloneRecompose [-...
Cmdlet Send-LinkedCloneRefresh Send-LinkedCloneRefresh [-Ma...
Cmdlet Send-LocalSessionRollback Send-LocalSessionRollback [-...
Cmdlet Send-SessionDisconnect Send-SessionDisconnect [[-Se...
Cmdlet Send-SessionLogoff Send-SessionLogoff [[-Sessio...
Cmdlet Send-VMReset Send-VMReset [-Machine_id <S...
Cmdlet Set-ImageRepository Set-ImageRepository [-Local_...
Cmdlet Set-License Set-License [-Key <String>] ...
Cmdlet Set-TransferServerMaintMode Set-TransferServerMaintMode ...
Cmdlet Update-AutomaticLinkedClonePool Update-AutomaticLinkedCloneP...
Cmdlet Update-AutomaticPool Update-AutomaticPool [-Pool_...
Cmdlet Update-ConnectionBroker Update-ConnectionBroker [-Br...
Cmdlet Update-GlobalSetting Update-GlobalSetting [-Sessi...
Cmdlet Update-ManualPool Update-ManualPool [-Pool_id ...
Cmdlet Update-ManualUnmanagedPool Update-ManualUnmanagedPool [...
Cmdlet Update-TerminalServerPool Update-TerminalServerPool [-...
Cmdlet Update-UserOwnership Update-UserOwnership [-Machi...
Cmdlet Update-ViewVC Update-ViewVC [-Vc_id <Strin...
Alright awesome! So it turns out that a lot of this actually matched up with the Horizon View PowerCLI 7 cmdlet Reference! But, back to the task at hand. Turns out there is actually only one command that was useful for me.
Get-EventReport
The rest wasn’t that useful to use for this task. The “Get-EventReport” cmdlet can give you quit some information, if you know how to use it. Before we can use this command it is useful to see what the command can deliver, you can check this by executing:
Get-EventReportList
report-name report-description
----------- ------------------
user_events User-initiated events. e.g.: login/log out of broker,launch desktop.
user_auth_failures User authentication failures e.g.: bad passwords, locked out, access de...
user_count_events Report on the maximum number of concurrent users logged in during the day
config_changes What changes were made to View Manager configuration settings (example:...
This tells us that we can get information from four categories. To get the same information that we can see in the VMware View Administrator console just execute the following piece of code:
Get-EventReport –ViewName user_count_events
report-result : 85
eventid : 4588106
module : Broker
eventtype : BROKER_DAILY_MAX_USERS
time : 2020-02-13 23:55:02.077
source : com.vmware.vdi.broker.events.loggers.maxsessiontracking.MaxSessionTimerTask
severity : INFO
moduleandeventtext : Over the past 24 hours, the maximum number of users with concurrent desktop sessions was 30
usercount : 30
Now the rest is easy, we will narrow this down to a specific number of days, because the rest isn’t needed for our use case. By doing this you will end up with the following piece of code:
Get-EventReport -ViewName user_count_events -startDate ((Get-Date).AddDays(-7)) | sort time | Select time, usercount
time usercount
---- ---------
2020-02-07 23:55:02.077 35
2020-02-07 23:55:02.077 35
2020-02-08 23:55:01.273 35
2020-02-08 23:55:01.273 35
2020-02-09 23:55:01.3 35
2020-02-09 23:55:01.3 35
2020-02-10 23:55:02.08 30
2020-02-10 23:55:02.08 30
2020-02-11 23:55:01.27 39
2020-02-11 23:55:01.27 39
2020-02-12 23:55:01.3 36
2020-02-12 23:55:01.3 36
2020-02-13 23:55:02.077 30
2020-02-13 23:55:02.077 30
The next thing we wanted to know was what user logged in at what time. This was for troubleshooting purposes because the VMware View Administrator console isn’t the fastest to display events, especially the older version of View. We started looking at the same command again and used the “user_events” ViewName type category. This resulted in many events. To sort through these it’s useful to check what type of events there are:
Get-EventReport –ViewName user_events | Select EventType –Unique
eventtype
---------
BROKER_USERLOGGEDIN
BROKER_USERLOGGEDOUT
Turns out, only two are available. This makes it easy to find out whether a user logged in succesfully or not. Just run the below command to find out when a user logged in.
Get-EventReport -ViewName user_events | ?{$_.EventType -eq "BROKER_USERLOGGEDIN" -AND $_.severity -eq "AUDIT_SUCCESS"}
So now that we have the information we need, we need to find a way to schedule this so that we can use this information, anytime we need it. Fortunately, scheduling PowerShell code is very easy. Just create a “.ps1” file and schedule it to run in Windows Task Manager. I ended up with the following script, which satisfied our needs.
#Start of script.
##########################################
# Author = Bryan van Eeden #
# Version = 1.0 #
# Date = 01/02/2020 #
##########################################
Add-PSSnapin VMware.View.Broker
$date = get-date -uformat '%m-%d-%Y-%H%M'
$filenamelocation = $("C:\temp\Loggedinusers_day" + $date + ".txt")
Get-EventReport -ViewName user_events -startDate ((Get-Date).AddDays(-6)) | ?{$_.eventtype -eq "BROKER_USERLOGGEDIN" -AND $_.severity -eq "AUDIT_SUCCESS"} | sort time | Select time, userdisplayname -Unique >> $filenamelocation
$filenamelocation2 = $("C:\temp\Concurrent_users" + $date + ".txt")
Get-EventReport -ViewName user_count_events -startDate ((Get-Date).AddDays(-7)) | sort time | Select time, usercount >> $filenamelocation2
#End of script.
Sample content of Loggedinusers_day_02-14-2020-0000.txt
time userdisplayname
---- ---------------
2020-02-08 04:55:40.793 vcloudvision.com\user01
2020-02-08 08:57:09.933 vcloudvision.com\user01
2020-02-08 09:32:46.127 vcloudvision.com\user01
2020-02-08 09:34:11.737 vcloudvision.com\user01
2020-02-08 09:51:03.68 vcloudvision.com\user01
2020-02-08 09:51:57.667 vcloudvision.com\user02
2020-02-08 11:09:35.55 vcloudvision.com\user03
2020-02-08 11:28:35.917 vcloudvision.com\user04
2020-02-08 12:31:33.997 vcloudvision.com\user02
2020-02-08 13:09:38.157 vcloudvision.com\user02
2020-02-08 13:09:45.233 vcloudvision.com\user02
2020-02-08 13:29:29.833 vcloudvision.com\user02
2020-02-08 14:06:54.623 vcloudvision.com\user02
Sample content of Concurrent_users_02-14-2020-0000.txt
time usercount
---- ---------
2020-02-07 23:55:02.077 35
2020-02-07 23:55:02.077 35
2020-02-08 23:55:01.273 35
2020-02-08 23:55:01.273 35
2020-02-09 23:55:01.3 35
2020-02-09 23:55:01.3 35
2020-02-10 23:55:02.08 30
2020-02-10 23:55:02.08 30
2020-02-11 23:55:01.27 39
2020-02-11 23:55:01.27 39
2020-02-12 23:55:01.3 36
2020-02-12 23:55:01.3 36
2020-02-13 23:55:02.077 30
2020-02-13 23:55:02.077 30
So there you have it. Even the ancient VMware View environment I was working on had ways to find our information that the VMware View Administrator console didn’t have. Hope you found this post useful!
2 Comments
Mohamed K, · January 23, 2021 at 5:21 pm
Hi Bryan,
Thank you for help about this topic. I found it very useful
How can add also add the Pool_Id of the user session, Please
time userdisplayname Pool_Id
—- ————— —————-
2020-02-08 04:55:40.793 vcloudvision.com\user01 Desktop Name
Thank you in advance for your help
Bryan van Eeden · May 1, 2021 at 3:20 pm
Hi Mohamed,
Good to hear that you liked the script! I am honestly not sure if that is possible since the Pool_ID is not a property within the user_events EventReport. So I am guessing you will have to correlate that data from another call and join it into the data from this script. I am currently no longer able to test this on a Horizon View 5.x environment unfortunately. So testing this for you will be difficult for now.