PowerCLI

 View Only
  • 1.  List Active Console Connections with PowerCLI

    Posted Jun 30, 2011 10:09 AM

    Does anyone know of a way to check the number of active console connections to a VM using PowerCLI?  I know it is possible to list connection events that have happened in the past but is it possible to check the current status of connections?  I have written a Powershell script to initiate a remote console connection to a VM but would like to ensure that there are no active connections already open on the selected VM.  I have already set the RemoteDisplay.MaxConnections=1 value in the VMX files to limit active connections to one.  Thanks in advance for any help.  



  • 2.  RE: List Active Console Connections with PowerCLI

    Posted Jun 30, 2011 11:57 AM

    Afaik, the list with active remote consoles is not kept on the vSphere server.

    But the event is logged.

    So you can extract the information from the events, something like thi for example

    Get-VIEvent -Start (Get-Date).AddMinutes(-30) -MaxSamples 9999 | `
    where {$_.GetType().Name -eq "VmRemoteConsoleConnectedEvent"} | `
    Select @{N="VM";E={$_.Vm.Name}},UserName,CreatedTime

    Although there also is a VmRemoteConsoleDisconnectedEvent event, I haven't been able to capture that.



  • 3.  RE: List Active Console Connections with PowerCLI
    Best Answer

    Posted Jun 30, 2011 12:12 PM

    Hello-

    I, too, do not know of a list with info about active connections, but there is at least a property that keeps the _count_ of active connections.  The "Runtime.NumMksConnections" property of the .Net View object of a VM holds that count:

    PS C:\> Get-VM myVM | Get-View -Property Name,Runtime.NumMksConnections | select Name,@{n="NumConn"; e={$_.Runtime.NumMksConnections}}

    Name       NumConn
    ----       -------
    myVM       1

    So, you could check that count, pmassey, and if it is "-eq 0", then initiate the connection...



  • 4.  RE: List Active Console Connections with PowerCLI

    Posted Jun 30, 2011 12:39 PM

    Thanks Matt, a count is all I need. This does the job perfectly! :smileyhappy: