Start a Conversation

Unsolved

This post is more than 5 years old

N

6622

December 6th, 2012 15:00

Powershell for removing disconnected users

Hey all,

Just wanted to share a simple script I use to remove hanging disconnected users from my farm.

Everything I've seen so far for dealing with disconnected users on vWorkspace has been directed to people using RDSH (using group policy if I remember correctly).  For those of us that don't use RDSH (I have desktops on vSphere myself) there didn't seem to be any solutions.  I have a pretty small environment still in it's testing phase so please use caution, etc, if you decide to borrow from this.

So using the new-ish PowerShell module 7.5.304.0071 I whipped up a simple script that I just run as a scheduled task.  The actual part of the script that disconnects users is at the bottom - the rest is to deal with the occasional issue of when a desktop that has a disconnected user gets suspended.  If you don't use power savings on your pool (and thus don't end up with suspended vm's) you can safely ignore that part.  I also love transcripts for PS scripts so if you don't you can remove that too!

Anyway, here is the code

#####################################################

#Remove_Disconnected.ps1

#

# Uses Quest vWorkspace PowerShell Module 7.5.304.0071

# Downloaded from http://en.community.dell.com/techcenter/virtualization/vworkspace/w/vworkspace-wiki/5750.quest-vworkspace-powershell-module-download

#

# Module Documentation currently avaiable at
# http://wiki.vworkspace.inside.quest.com/index.php/Main_Page

#

# Version .1 - 12-04-2012

#

#####################################################

$ErrorActionPreference="SilentlyContinue"

Stop-Transcript | out-null

$ErrorActionPreference = "Continue"

$trans = "C:\scripts\logs\" + (Get-Date -Format MM-dd-yyyy) + "-remove-disconnected-log.txt"

Start-Transcript -path $trans -append | out-null

Import-Module Quest.vWorkspace.PowerShellModule 

$farm = 'vWorkspace Database'

$resume = 0

Connect-QVWfarm $farm

#See if there are any Paused computers that have logged on users

$paused = Get-QVWcomputer -filter{$QVWComputer.Status.PowerState -eq 'Paused' } -Farm $farm

if($paused){

     foreach($comp in $paused){

          if($comp.Status.CurrentUser -ne 'None') {

                    write-host "Waking up:" $comp.Name.ToString()

                    Invoke-QVWComputerAction -Identity $comp -Action Resume -Farm $farm

                    $resume ++

          }

     }#end foreach

}#end $paused if

#Sleep while machines wake up

if($resume -ge 1){

          $seconds = 60 + (($resume-1)*20) #60 seconds for the first comp and 20 seconds for each additional

          Write-Host "Sleeping for $seconds seconds"

          Start-Sleep -Seconds $seconds

}#end sleep if

#See if any users are disconnected

$discon = Get-QVWcomputer -filter{$QVWComputer.Status.LogonState -eq 'Disconnected'} -Farm $farm

if($discon){

          foreach($comp in $discon) {

                    write-host $comp.Status.CurrentUser.ToString() "will be logged off from" $comp.Name.ToString()

                    Invoke-QVWComputerAction -Identity $comp -Action LogoffUser -Farm $farm

          }

}#end $discon if

Stop-Transcript | out-null

No Responses!
No Events found!

Top