«

»

Feb 07 2012

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.

image

 

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:

  • AGENT_CONNECTED
  • AGENT_DISCONNECTED
  • AGENT_ENDED
  • AGENT_PENDING
  • AGENT_PENDING_EXPIRED
  • AGENT_RECONFIGURED
  • AGENT_RECONNECTED
  • AGENT_RESUME
  • AGENT_SHUTDOWN
  • AGENT_STARTUP
  • AGENT_SUSPEND
  • refer to the VMware View 5.0 Integration Guide for more information

image

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 - myvirtualcloud.net

   4: #

   5: # EXAMPLE

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

   7: ######

   8:  

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

  10:  

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

  12:     write "Missing Parameters";exit

  13:     }

  14:     

  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($_.cn,$_.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.($_.name)}} | Where-Object {$_.hostname} | Format-Table *

 

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

Similar Posts:

Permanent link to this article: http://myvirtualcloud.net/?p=2882

11 comments

Skip to comment form

  1. Beew

    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?

  2. Andre Leibovici

    @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 *

    or

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

    Regards,
    Andre

  3. burak ç?nar

    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

  4. Andre Leibovici

    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.

    -Andre

  5. itismi

    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
    n
    + FullyQualifiedErrorId : ExceptionInGetEnumerator

    View 5.2

  6. Eddie Sardinha (@esardinha08)

    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.

  7. Eddie

    Can anyone assist?

  8. Andre Leibovici

    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

  9. Mark Baker

    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.

  10. Andre Leibovici

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

  11. Terry Mercer

    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