How to get VMware View Desktop Login Count

I was reading tweets today and someone asked for a way to retrieve how often desktops are used – how many times users log into virtual desktops. I am not sure the reason behind the request but this is possible via the VMware View PowerCLI command Get-EventReport.

Get-EventReport -viewName user_events | Where {$_.eventtype -eq "AGENT_CONNECTED"} | Group-Object machineid | Format-Table *

The problem with Get-EventReport is that the output is the machineid property, not allowing administrator to identify the virtual desktops.



I created a script that leverages the work Clint Kitson did while creating the VMware View Pool Membership Management using PowerCLI. The key to make this work is to query the local ADAM database to uncover the relationship between machineid and the real name of the desktop (ipHostNumber).

Download the scripts here, and keep them in the same folder in one of the View connection servers. To execute use:

.\get_vm_login_count.ps1 -username "username" -password "password" -connectionbroker ipaddress

The result will be a list of desktops (hostname) and the total number of times each desktop was used. This is determined by the eventtype AGENT_CONNECTED. You may also use the parameter –eventtype to choose from the possible list of VMware View events:

  • refer to the VMware View 5.0 Integration Guide for more information


The script will automatically produce results for this year, but the parameter –startdate can also be used to provide a specific date or a date range.

   1: #####

   2: ## 09/30/2011

   3: # Andre Leibovici - @andreleibovici -

   4: #

   5: # EXAMPLE

   6: # .\get_vm_login_count -username "admin" -password "password" -connectionbroker

   7: ######


   9: Param ($username="", $password="", $connectionbroker="", $startdate=(Get-Date -Day 01 -Month 01 -Hour 0 -Minute 0 -Second 0), $eventtype="AGENT_CONNECTED")


  11: if((!$username -or !$password)) {

  12:     write "Missing Parameters";exit

  13:     }


  15: $cn = $null

  16: $cn = @{}

  17: $cns = .\custom_vmware_view_ps.ps1 -username $username -password $password -connectionbroker $connectionbroker -action view-get-objects -ou servers | %{

  18: $cn.add($,$_.ipHostNumber)

  19: }

  20: $event = Get-EventReport -viewName user_events -startDate $startdate | Where {$_.eventtype -eq $eventtype}

  21: $event | Group-Object machineid | Select-Object *,@{n="hostname";e={$cn.($}} | Where-Object {$_.hostname} | Format-Table *


This article was first published by Andre Leibovici (@andreleibovici) at Visit for more articles about Virtualization, VDI and End User Computing.


Skip to comment form

    • Beew on 02/08/2012 at 12:32 am

    This is a something we’ve been looking for. Hopefully it can help us charge users/departments based on the number of times they’ve been using certain VM’s, but the we would have to know the usernames as well. Is it possible to retrieve the usernames as well with this script?

  1. @Beew
    You can use the cmdlets below to retrieve the amount of times each user has logged in.

    Get-EventReport -viewName user_events | Group-Object userdisplayname | Format-Table *


    Get-EventReport -viewName user_events | Group-Object userdisplayname, machineid | Format-Table *


  2. i got an error when i try to run ps.
    i’m using view 5.1

    The term ‘Get-EventReport’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is co
    rrect and try again.
    At C:\Users\user\Desktop\get_vm_login_count.ps1:20 char:25
    + $event = Get-EventReport <<<< -viewName user_events -startDate $startdate | Where {$_.eventtype -eq $eventtype}
    + CategoryInfo : ObjectNotFound: (Get-EventReport:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

  3. burak ç?nar, It seems to me you have not loaded the View PoserShell Module. You should start a PowerShell shell session using the shortcut View places in your server.


    • itismi on 10/03/2013 at 4:16 pm

    Any suggestions on

    The following exception was thrown when trying to enumerate the collection: “Th
    ere is no such object on the server.
    At %path%\custom_vmware_view_ps.ps1:46 char:5
    + <<<< $ouObj.psbase.get_children() | %{ $_ }
    + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemExceptio
    + FullyQualifiedErrorId : ExceptionInGetEnumerator

    View 5.2

  4. When I run .\get_vm_login_count.ps1 -username “username” -password “password” -connectionbroker ipaddress it asks me if I want to run the script and keeps asking after I hit yes. Any suggestions? I have powercli 5.1.0 installed on the connection server.

    • Eddie on 01/14/2014 at 12:32 pm

    Can anyone assist?

  5. Eddi, have you enable scripts to run in your PowerShell environment? If not, make sure you open PowerShell command-line as administrator and run :

    Set-ExecutionPolicy RemoteSigned

    • Mark Baker on 03/26/2014 at 8:25 am

    Is the View PowerCLI still available anywhere for download? All I can find is the vSphere PowerCLI which does not have the get-eventreport cmdlet required for this.

  6. Mark Baker, View PowerCLI modules are installed with Horizon View Connection Server installation.

    • Terry Mercer on 04/05/2014 at 5:31 pm

    How can I output the results to a .cvs file? I tried | export-csv c:\file.csv and it gives me only a partial printout. Any suggestions. Thanks. Also thanks for the script.

Leave a Reply