Public/Hide-StuckUser.ps1

Function Hide-StuckUser {
    <#
        .SYNOPSIS
            Hide stuck user sessions so they can log on to another XenApp server.
        .DESCRIPTION
            Running this PowerShell command, you will have the affected user up and running quickly and you can worry about draining
            and restarting the server at a more convenient time or without as much urgency.
        .PARAMETER UserName
            Username of affected user
        .EXAMPLE
            PS C:\> Hide-StuckUser -UserName 'DOMAIN\AffectedUsername'
        .NOTES
            Based on the article found here: http://www.jgspiers.com/user-stuck-citrix-desktop-force-log-off
    #>

    [CmdletBinding(
        ConfirmImpact = 'Medium',
        PositionalBinding = $false
    )]
    param (
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = 'Username of affected user'
        )]
        [ValidateNotNullOrEmpty()]
        [Alias('user')]
        [string]$UserName
    )

    Begin { }
    Process {
        Try {
            Get-BrokerSession -UserName $UserName | Set-BrokerSession -Hidden $true -ErrorAction Stop
        } Catch {
            Write-Warning $_.Exception.Message
        }
        break
    }
    End {
        Remove-Variable UserName
    }
}