Translate

donderdag 29 augustus 2013

Terminate idle sessions Vsphere client

Ever wondered why the sessions are kept within Vsphere client? the idle timer is set for 30 minutes. But the're always sessions left with idle time far over the 30 mins....

Create a edited shortcut of vpx client. Edit the target line:

"C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" -inactivityTimeout 90

With this at the end the session will be ended after 90 minutes.

It's also possible trough PowerCLI.

This option is to list all sessions:

Function Get-ViSession {
    <#
        .SYNOPSIS
            Lists vCenter Sessions.

        .DESCRIPTION
            Lists all connected vCenter Sessions.

        .EXAMPLE
            PS C:\> Get-VISession

        .EXAMPLE
            PS C:\> Get-VISession | Where { $_.IdleMinutes -gt 5 }
    #>
    $SessionMgr = Get-View $DefaultViserver.ExtensionData.Client.ServiceContent.SessionManager
    $AllSessions = @()
    $SessionMgr.SessionList | Foreach {   
        $Session = New-Object -TypeName PSObject -Property @{
            Key = $_.Key
            UserName = $_.UserName
            FullName = $_.FullName
            LoginTime = ($_.LoginTime).ToLocalTime()
            LastActiveTime = ($_.LastActiveTime).ToLocalTime()
           
        }
            If ($_.Key -eq $SessionMgr.CurrentSession.Key) {
                $Session | Add-Member -MemberType NoteProperty -Name Status -Value "Current Session"
            } Else {

                $Session | Add-Member -MemberType NoteProperty -Name Status -Value "Idle"
            }
            $Session | Add-Member -MemberType NoteProperty -Name IdleMinutes -Value ([Math]::Round(((Get-Date) – ($_.LastActiveTime).ToLocalTime()).TotalMinutes))
    $AllSessions += $Session
    }
    $AllSessions
}



This option is to end al sessions above 30 minutes:

Connect-VIServer vsphereserver -User username -Password pwd

Function Disconnect-ViSession { 
       [CmdletBinding()] 
    Param ( 
        [Parameter(ValueFromPipeline=$true)] 
        $SessionList 
    ) 
    Process { 
        $SessionMgr = Get-View $DefaultViserver.ExtensionData.Client.ServiceContent.SessionManager 
        $SessionList | Foreach { 
            Write "Disconnecting Session for $($_.Username) which has been active since $($_.LoginTime)" 
            $SessionMgr.TerminateSession($_.Key) 
        } 
    } 
}
Get-VISession | Where { $_.IdleMinutes -gt 30 } | Disconnect-ViSession





What's this all about. The VPX client service is using RAM on your Vcenter server with every session it will increase. So it's usefull to keep it clean.