Hi,
Please help me disconnect particular user whose idle session is 30 mins
## max number of idle minutes for sessions to keep
$intOlderThan = 30
$serviceInstance = Get-View 'ServiceInstance'
## get the session manager object
$sessMgr = Get-View $serviceInstance.Content.sessionManager
## array to hold info about stale sessions
$oldSessions = @()
foreach ($sess in $sessMgr.SessionList){
if (($sess.LastActiveTime).addminutes($intOlderThan) -lt (Get-Date) -and
$sess.Key -ne $sessMgr.CurrentSession.Key){
$oldSessions += $sess.Key
} ## end if
} ## end foreach
## if there are any old sessions, terminate them; else, just write message to the Warning stream
if (($oldSessions | Measure-Object).Count -gt 0) {
## Terminate sessions than are idle for longer than approved ($intOlderThan)
$sessMgr.TerminateSession($oldSessions)
} ## end if
else {Write-Warning "No sessions that have been idle for more than '$intOlderThan' minutes; no action taken"}