Sunday, September 12, 2021

Log Off Idle Citrix Sessions

The simple PowerShell snippet below will log off any session that has been idle for more than the specified number of hours.


# sessions that have been idle for longer than 
# the below number of hours will be logged off
$maxIdleHours = 24

# load the Citrix snapin
Add-PSSnapin Citrix*

# function to calculate the number of hours
# that a session has been idle
Function Get-IdleHours {
    param ([TimeSpan] $IdleTime)
    ($IdleTime.Days * 24) + $IdleTime.Hours
}

# get sessions that are idle
$sessions = @(Get-Brokersession | ? IdleDuration -ne $null)

# cycle through the list, and log off sessions that
# have been idle for > the specified number of hours
foreach ($sess in $sessions) {
    if ((Get-IdleHours($sess.IdleDuration)) -gt $maxIdleHours) {
        Stop-BrokerSession $sess
    }
}


Sam Jacobs is the Director of Technology at Newtek Technology Systems (formerly IPM), the longest standing Citrix Platinum Partner on the East Coast. With more than 30 years of IT consulting, Sam is a NetScaler and StoreFront customizations and integrations industry expert. He holds Microsoft and Citrix certifications, and is the editor of TechDevCorner.com, a technical resource blog for IT professionals. He is one of the top Citrix support Forum contributors, and has earned industry praise for the tools he has developed to make NetScaler, StoreFront and Web Interface easier to manage for administrators and more intuitive for end users. Sam became a Citrix Technology Professional (CTP) in 2015, and can be reached at: sjacobs@newtekone.com or on Twitter at: @WIGuru.

No comments:

Post a Comment