Hello,
I suspect that you might be running into a situation where you have no sessions that have been inactive for longer than the configured time. To help rule that in/out, you could add a check for the number of sessions held in the $oldSessions array -- if greater than 0, then try to terminate them, else, write to the Warning stream that there are no such sessions to terminate. Updated/consolidated a bit:
## max number of idle minutes for sessions to keep
$intOlderThan=60
$serviceInstance=Get-View'ServiceInstance'
## get the session manager object
$sessMgr=Get-View$serviceInstance.Content.sessionManager
## array to hold info about stale sessions
$oldSessions= @()
foreach ($sessin$sessMgr.SessionList){
if (($sess.LastActiveTime).addminutes($intOlderThan) -lt (Get-Date)){
$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 -gt0) {
## 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"}
How does that do for you?