VMware Horizon Community
clichtenberg2
Contributor
Contributor

Determine Disconnect time for VDI

Good Afternoon,

I am looking for a way to determine how long a desktop (VM) has been in a disconnect state.   We use Horizon 6.2 and our standard autologoff time is 120 minutes.  Determining the time in the state would help in freeing  up desktops manually during an emergency.   Would this be a scripted action or is there some math that can be done with start time, duration and last session?

2 Replies
jrodsguitar
Enthusiast
Enthusiast

This will get you close so figure out the rest. Obviously you'll need PowerCLI 6.5

#Start of Script

#This is a quick script (10 minutes) I whipped up to get session status of HV connected users.

#Use this at your own risk. I'm not responsible if you run this in your environment and everything breaks.

#I do not have any certs/degrees/diplomas/medals or any of that crap when it comes to a formal education on any of this to include Windows/VMWare/IT/Technology.

#Unlike everyone else running around these forums I'm not a professional but if they can whip this script up in 10 minutes they deserve a medal ;). Everything below is strictly from good ole fashioned trial and error.

#Jose Rodriguez

#Import Modules

Import-Module VMware.VimAutomation.HorizonView

Import-Module VMware.VimAutomation.Core

#Get Credentials if not exist

if($cred -eq $null){

$cred = Get-Credential

}

#Specify and Connect to Horizon Server if not conected

$viewserver = 'NAME_OF_YOUR_HORIZON_CONNECTION_SERVER_GOES_HERE'

if($connectviewserver -eq $null){

$connectviewserver = Connect-HVServer -server $viewserver -Credential $cred

}

#Do crap

$hvapi = $global:DefaultHVServers[0].ExtensionData

$queryservice = New-Object 'Vmware.Hv.QueryServiceService'

$querydefinition = New-Object 'Vmware.Hv.QueryDefinition'

$querydefinition.queryEntityType = 'SessionLocalSummaryView'

$Sessions = $queryservice.QueryService_Query($hvapi,$querydefinition)

$sessionsobject = $sessions.Results

$finalobj = @()

foreach ($session in $sessionsobject){

$properties = @{

UserName = $Session.namesdata.UserName

poolname = $Session.NamesData.desktopname

desktopname = $Session.NamesData.MachineOrRDSServerDNS

sessionState = $Session.sessiondata.sessionstate

sessionstarttime = $Session.sessiondata.starttime

sessiondisconnecttime = $Session.sessiondata.disconnecttime

}

$finalobj += new-object pscustomobject -Property $properties

}

#output the results

$finalobj

#End of script

Output example:

sessiondisconnecttime : 1/23/2018 4:44:42 PM

sessionState          : DISCONNECTED

poolname              : Pool-Name-blah-blah

UserName              : blah\someusername

desktopname           : somedesktopwillbehere

sessionstarttime      : 1/23/2018 5:04:26 AM

Blog: https://powershell.house/
Reply
0 Kudos
clichtenberg2
Contributor
Contributor

Thanks we'll try this in our test environment.