jmatz135
Hot Shot
Hot Shot

Logoff Multiple Sessions from View Administrator

In Horizon View 7.x is there a way to logoff multiple sessions at once?  If I select multiple sessions and then select logoff it displays the warning for the first desktop that I click OK on and it logs off that desktop, but all of the other desktops it does nothing to.

0 Kudos
5 Replies
rseekell
Enthusiast
Enthusiast

You can do this with PowerShell, but I have not found a way to do it in the GUI.  PowerShell for Horizon takes several steps to set up, but then it's pretty easy. If you are interested, then I can go into detail.

0 Kudos
jmatz135
Hot Shot
Hot Shot

They really need to add that functionality to the GUI. 

Anyway, I have the Horizon View for Power CLI installed but if you have the commands real quick to loop through a pool and log off the desktops that would be great.

0 Kudos
rseekell
Enthusiast
Enthusiast

OK, do you have the HVHelper module from PowerCLI-Example-Scripts/Modules/VMware.Hv.Helper at master · vmware/PowerCLI-Example-Scripts · GitH... ?  It's a lot easier than using the API.

0 Kudos
jmatz135
Hot Shot
Hot Shot

I do now. 

0 Kudos
rseekell
Enthusiast
Enthusiast

<#

Log off all logged on sessions in one pool in vmware Horizon environment

Enter the poolname, and it will confirm if you want to log off each desktop, although you can answer YesToAll

This script is provided AS IS - with no warranties

Please review any script and test it before running in a production environment

#>

[cmdletbinding(SupportsShouldProcess, ConfirmImpact="high")]

Param (

    [Parameter(Mandatory)][string]$PoolName,

    [Parameter(Mandatory)][string]$myHorizonConnectionServer

)

#region initialConnect

if ($hvservices -eq $null) {

    Import-Module VMware.VimAutomation.HorizonView

    Import-Module VMware.Hv.Helper

    $hvconnection = Connect-HVServer $myHorizonConnectionServer

    $hvservices = $hvconnection.ExtensionData

}

#endregion

#get only connected desktops in a pool, summary data only

$poolDesktops = Get-HVMachineSummary -PoolName $PoolName -State CONNECTED

#skipping disconnected and error states, not to mention machines with no session

foreach ($desktop in $poolDesktops) {

    #second, get session off desktop

    $sessionID = $desktop.Base.Session

    if ($null -ne $sessionID) { #confirm session ID

        if ($PSCmdlet.ShouldProcess($desktop.base.name)) { #user may confirm or use whatIf

            $hvservices.Session.Session_Logoff($sessionID) #send logoff command

        }

        #else take no action

    }

    else {

        Write-Error "Could not get session ID from desktop; maybe no one is logged on"

    }

}#end foreach

Please let me know how this works for you.

0 Kudos